:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f4f8);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #0f172a);
  --sub: #475569;
  --hint: #64748b;
  --sep: rgba(15, 23, 42, 0.08);
  --fill: rgba(15, 23, 42, 0.045);
  --fill-2: rgba(15, 23, 42, 0.085);

  --brand: #2f6bff;
  --brand-2: #4e84ff;
  --brand-soft: rgba(47, 107, 255, 0.12);
  --brand-ink: #1e4ed8;
  --brand-grad: linear-gradient(135deg, #2f6bff 0%, #5b8eff 100%);

  --ok: #0d9458;
  --ok-bg: rgba(13, 148, 88, 0.12);
  --warn: #b45309;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --bad: #dc2626;
  --bad-bg: rgba(220, 38, 38, 0.12);

  --glass: rgba(255, 255, 255, 0.93);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 0 0 1px rgba(15, 23, 42, 0.045);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --r-lg: 20px;
  --r: 16px;
  --r-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}

:root[data-scheme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #0b0d13);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #151821));
  --text: var(--tg-theme-text-color, #f1f5f9);
  --sub: #cbd5e1;
  --hint: #94a3b8;
  --sep: rgba(255, 255, 255, 0.08);
  --fill: rgba(255, 255, 255, 0.05);
  --fill-2: rgba(255, 255, 255, 0.09);

  --brand: #4b83ff;
  --brand-2: #76a3ff;
  --brand-soft: rgba(75, 131, 255, 0.16);
  --brand-ink: #8cb2ff;

  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, 0.15);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.15);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, 0.15);

  --glass: rgba(21, 24, 33, 0.93);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 0.9em; }
.num { font-variant-numeric: tabular-nums; }

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--sep);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-grad); color: #fff;
  box-shadow: 0 4px 14px rgba(47, 107, 255, 0.3);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text { min-width: 0; }
.brand-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 16px; font-weight: 700; letter-spacing: -0.02em;
}
.brand-tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 6px; border-radius: 6px;
  background: var(--brand-soft); color: var(--brand-ink);
}
.brand-sub {
  font-size: 12px; color: var(--hint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--fill); color: var(--text);
  transition: transform 120ms ease, background-color 120ms ease;
}
.icon-btn:active { transform: scale(0.92); background: var(--fill-2); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spinning svg { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main container ── */
.app-main {
  padding: 14px 16px calc(92px + var(--safe-bottom));
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px 0;
  font-size: 13px; font-weight: 650; color: var(--hint);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ── Cards & Pills ── */
.card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.card-tight { padding: 0; overflow: hidden; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--brand-soft); color: var(--brand-ink); }
.pill.mute { background: var(--fill-2); color: var(--sub); }

/* ── Hero Status Banner ── */
.status-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-radius: var(--r);
  background: var(--card); box-shadow: var(--shadow);
}
.status-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg);
}
.pulse-dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-bg); }
.pulse-dot.bad { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-bg); }
.status-title { font-weight: 650; font-size: 15px; }
.status-sub { font-size: 12.5px; color: var(--hint); }

/* ── KPI 2x2 Grid ── */
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi-card {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 13px 14px; display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: 12.5px; font-weight: 500; color: var(--hint); }
.kpi-val {
  font-size: 26px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 12px; line-height: 1.3; color: var(--sub); }

/* ── 7-day Bar Chart ── */
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.chart-title { font-weight: 650; font-size: 15px; }
.chart-legend { font-size: 12px; color: var(--hint); }
.chart-bars {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end; gap: 8px; height: 108px; padding-top: 18px;
}
.chart-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-val { font-size: 11px; font-weight: 600; color: var(--hint); font-variant-numeric: tabular-nums; }
.chart-track {
  width: 100%; max-width: 28px; flex: 1; display: flex; align-items: flex-end;
  background: var(--fill-2); border-radius: 8px; overflow: hidden;
}
.chart-fill {
  width: 100%; border-radius: 8px;
  background: var(--brand-grad);
  min-height: 4px; transition: height 300ms ease;
}
.chart-day { font-size: 11px; color: var(--hint); font-variant-numeric: tabular-nums; }

/* ── Quick Actions 2x2 ── */
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; border-radius: var(--r);
  background: var(--card); box-shadow: var(--shadow);
  text-align: left; transition: transform 120ms ease;
}
.quick-btn:active { transform: scale(0.97); }
.quick-ico {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink);
}
.quick-ico.ok { background: var(--ok-bg); color: var(--ok); }
.quick-ico.warn { background: var(--warn-bg); color: var(--warn); }
.quick-ico.bad { background: var(--bad-bg); color: var(--bad); }
.quick-ico svg { width: 18px; height: 18px; }
.quick-txt b { display: block; font-size: 14px; font-weight: 650; }
.quick-txt span { display: block; font-size: 12px; color: var(--hint); }

/* ── Service Health Rows ── */
.kv-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px; border-top: 1px solid var(--sep);
}
.kv-row:first-child { border-top: 0; }
.kv-left { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.kv-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.kv-dot.bad { background: var(--bad); }
.kv-dot.mute { background: var(--hint); }
.kv-val { font-size: 13.5px; color: var(--sub); text-align: right; font-variant-numeric: tabular-nums; }

/* ── Segmented Control & Chips ── */
.seg {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px; border-radius: 13px; background: var(--fill-2); gap: 3px;
}
.seg-btn {
  height: 34px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  color: var(--sub); transition: all 150ms ease;
}
.seg-btn.active {
  background: var(--card); color: var(--text);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.chips {
  display: flex; gap: 8px; overflow-x: auto;
  margin: 0 -16px; padding: 2px 16px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips-grid-3 {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px; margin-bottom: 10px;
}
.chips-grid-3 .chip { justify-content: center; padding: 0 8px; font-size: 12.5px; }
.chip {
  flex: none; height: 34px; padding: 0 13px; border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600; color: var(--sub);
  display: inline-flex; align-items: center; gap: 5px;
  transition: transform 120ms ease;
}
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(47, 107, 255, 0.25); }
.chip-n {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: var(--fill-2); color: inherit;
}
.chip.active .chip-n { background: rgba(255, 255, 255, 0.22); }

/* ── Platforms List ── */
.plat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--sep);
}
.plat-row:first-child { border-top: 0; }
.plat-ico {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 19px;
  background: var(--fill);
}
.plat-main { flex: 1; min-width: 0; }
.plat-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.plat-name { font-weight: 650; font-size: 15px; white-space: nowrap; }
.plat-nums { font-size: 12px; color: var(--sub); font-variant-numeric: tabular-nums; white-space: nowrap; }
.plat-bar { height: 5px; border-radius: 5px; background: var(--fill-2); overflow: hidden; margin-top: 6px; }
.plat-bar i { display: block; height: 100%; border-radius: 5px; background: var(--ok); }
.plat-bar.mid i { background: var(--warn); }
.plat-bar.low i { background: var(--bad); }

/* ── iOS Toggle Switch ── */
.switch {
  position: relative; width: 48px; height: 28px; flex: none;
  border-radius: 999px; background: rgba(100, 116, 139, 0.26);
  transition: background-color 180ms ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.switch.on { background: var(--ok); }
.switch.on.warn-tone { background: var(--warn); }
.switch.on::after { transform: translateX(20px); }

/* ── Users List ── */
.summary-strip {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 12px 14px;
}
.summary-strip div b { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-strip div span { font-size: 12px; color: var(--hint); }

.user-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 16px; border-top: 1px solid var(--sep); text-align: left;
  transition: background-color 120ms ease;
}
.user-row:first-child { border-top: 0; }
.user-row:active { background: var(--fill); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  background: var(--brand-grad);
}
.avatar.lg { width: 54px; height: 54px; font-size: 20px; }
.avatar.banned { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.user-main { flex: 1; min-width: 0; }
.user-name {
  font-weight: 650; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-sub {
  font-size: 12.5px; color: var(--hint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: none; }
.user-time { font-size: 11px; color: var(--hint); font-variant-numeric: tabular-nums; }

/* ── Errors ── */
.err-card {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.err-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.err-url {
  font-family: var(--mono); font-size: 12px; color: var(--brand-ink);
  overflow-wrap: anywhere; background: var(--fill); padding: 6px 8px; border-radius: 8px;
}
.err-msg { font-size: 13px; color: var(--bad); word-break: break-word; }

/* ── Forms & Action Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; padding: 0 16px; border-radius: var(--r-sm);
  font-weight: 650; font-size: 14px;
  background: var(--fill); color: var(--text);
  transition: transform 120ms ease, opacity 120ms ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--brand-grad); color: #fff; }
.btn.ok { background: var(--ok-bg); color: var(--ok); }
.btn.warn { background: var(--warn-bg); color: var(--warn); }
.btn.bad { background: var(--bad-bg); color: var(--bad); }
.btn.solid-bad { background: var(--bad); color: #fff; }
.btn.full { width: 100%; }
.btn-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.btn-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.field {
  width: 100%; border-radius: var(--r-sm); border: 1px solid var(--sep);
  background: var(--fill); padding: 10px 12px;
  color: var(--text); outline: none; resize: none;
}
.field:focus { border-color: var(--brand); background: var(--card); }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--hint); margin: 10px 0 6px; }
.field-label:first-child { margin-top: 0; }

.progress-track { height: 8px; border-radius: 999px; background: var(--fill-2); overflow: hidden; margin: 10px 0 6px; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--brand-grad); transition: width 250ms ease; }

/* ── Floating Tabbar ── */
.tabbar {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(10px + var(--safe-bottom)); z-index: 40;
  max-width: 656px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 6px; border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--sep);
}
.tab-btn {
  position: relative; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; height: 50px; border-radius: 16px;
  color: var(--hint); font-size: 11px; font-weight: 600;
  transition: color 150ms ease, background-color 150ms ease, transform 120ms ease;
}
.tab-btn:active { transform: scale(0.94); }
.tab-btn svg { width: 20px; height: 20px; }
.tab-btn.active { color: var(--brand-ink); background: var(--brand-soft); }
.tab-badge {
  position: absolute; top: 5px; right: calc(50% - 18px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--bad); color: #fff; font-style: normal;
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}

/* ── Bottom Sheet ── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(22px + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  animation: sheet-up 220ms cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes sheet-up { from { transform: translateY(32px); opacity: 0.7; } to { transform: none; opacity: 1; } }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--fill-2); margin: 0 auto 14px;
}

/* ── Toast & Empty & Skeleton ── */
.toast-root {
  position: fixed; top: calc(14px + var(--safe-top)); left: 16px; right: 16px;
  z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  color: #fff; background: #0f172a; box-shadow: var(--shadow-lg);
  animation: toast-in 200ms ease;
}
.toast.ok { background: #0d9458; }
.toast.bad { background: #dc2626; }
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 28px 18px; text-align: center; color: var(--hint);
}
.empty b { display: block; font-size: 16px; color: var(--text); margin-bottom: 4px; }

.skel {
  height: 92px; border-radius: var(--r);
  background: linear-gradient(90deg, var(--card) 25%, var(--fill) 50%, var(--card) 75%);
  background-size: 200% 100%; animation: skel 1.2s infinite;
}
@keyframes skel { to { background-position: -200% 0; } }
