:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #232e3c);
  --card: var(--tg-theme-section-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #64b5ef);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --border: rgba(255, 255, 255, 0.08);
  --danger: #e05a5a;
  --ok: #4caf7d;
  --warn: #e0a24a;
}

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

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

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 600; font-size: 17px; white-space: nowrap; }
.panel-select { margin-left: auto; min-width: 0; }
.icon-btn {
  flex: 0 0 auto; background: none; border: none; color: var(--text);
  font-size: 20px; padding: 4px 2px; cursor: pointer; line-height: 1;
}
.icon-btn:active { opacity: .6; }
.panel-select select {
  max-width: 55vw;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 14px;
}

/* View */
.view { flex: 1; padding: 12px 14px 90px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card.tap:active { opacity: 0.7; }

.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.muted { color: var(--hint); font-size: 13px; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge.ok { background: rgba(76,175,125,.18); color: var(--ok); }
.badge.off { background: rgba(224,90,90,.18); color: var(--danger); }
.badge.warn { background: rgba(224,162,74,.18); color: var(--warn); }

/* Search */
.searchbar { position: relative; margin-bottom: 12px; }
.searchbar input {
  width: 100%; padding: 12px 14px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border: none; border-radius: 10px;
  background: var(--btn); color: var(--btn-text);
  font-size: 15px; font-weight: 600; cursor: pointer; width: 100%;
}
.btn:active { opacity: .8; }
.btn.secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; }

.fab {
  position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--btn); color: var(--btn-text);
  font-size: 28px; border: none; z-index: 20;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}

/* Forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 11px 12px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; font-size: 15px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 20px; font-size: 14px;
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
}
.chip.active { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat-box .num { font-size: 22px; font-weight: 700; }
.stat-box .lbl { color: var(--hint); font-size: 12px; margin-top: 2px; }
.stat-box.full { grid-column: 1 / -1; }

.bar-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.bar-line:last-child { border-bottom: none; }

/* Metrics */
.meter { height: 6px; border-radius: 4px; background: var(--bg); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--ok); }
.meter.warn > i { background: var(--warn); }
.meter.crit > i { background: var(--danger); }
.metric-row { display: flex; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--hint); flex-wrap: wrap; }

.section-title { font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; margin: 16px 2px 8px; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: flex; background: var(--bg2);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--hint);
  padding: 8px 0 10px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab .ic { font-size: 20px; }
.tab.active { color: var(--link); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: #0008; z-index: 50;
  display: flex; align-items: flex-end;
}
.modal {
  background: var(--bg); width: 100%; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
.modal h3 { margin: 0; }
.modal-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
  position: sticky; top: -18px; background: var(--bg); padding: 4px 0 8px; z-index: 2;
}
.modal-head h3 { flex: 1; min-width: 0; }
.modal-close {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  border: none; background: var(--bg2); color: var(--text);
  font-size: 16px; line-height: 1; cursor: pointer;
}
.modal-close:active { opacity: .7; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

.empty { text-align: center; color: var(--hint); padding: 40px 20px; }
.spinner { text-align: center; color: var(--hint); padding: 30px; }

.loading-bar { height: 2px; background: var(--btn); animation: load 1s infinite; }
@keyframes load { 0%{opacity:.3} 50%{opacity:1} 100%{opacity:.3} }
