:root {
  --bg: #0b1016;
  --bg2: #121a24;
  --card: #151f2b;
  --card2: #1b2735;
  --line: #22303f;
  --text: #e8eef5;
  --muted: #8fa3b8;
  --green: #3ecf8e;
  --yellow: #f5c451;
  --orange: #f79d3c;
  --red: #ef5b5b;
  --blue: #4aa8ff;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app { max-width: 1100px; margin: 0 auto; padding: 12px 12px 28px; }

.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); padding-bottom: 8px; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
h1 { font-size: 18px; letter-spacing: .12em; margin: 6px 0 2px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--card2); border: 1px solid var(--line); white-space: nowrap;
}
.icon-btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; width: 34px; height: 34px; font-size: 17px; cursor: pointer;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
}
.tab.active { background: var(--blue); border-color: var(--blue); color: #06121f; font-weight: 600; }
.tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; cursor: pointer; transition: border-color .15s, transform .1s;
}
.card:active { transform: scale(.995); }
.card:hover { border-color: #33485d; }
.card.offline { opacity: .55; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-name { font-weight: 600; }
.card-sub { font-size: 12px; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.status-dot.on { background: var(--green); box-shadow: 0 0 8px rgba(62,207,142,.7); }
.status-dot.off { background: var(--red); }

.gauge-row { display: flex; align-items: center; gap: 14px; margin: 12px 0 10px; }
.gauge { position: relative; width: 78px; height: 78px; flex: 0 0 auto; }
.gauge svg { transform: rotate(-90deg); }
.gauge .val {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700;
}
.gauge-meta { flex: 1 1 auto; min-width: 0; }

.metric { margin-bottom: 7px; }
.metric-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.bar { height: 6px; background: #0d151d; border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; transition: width .4s ease; }

.net-row { display: flex; justify-content: space-between; font-size: 12px; margin-top: 8px; }

.spark { width: 100%; height: 34px; display: block; margin-top: 8px; }

.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.back-btn {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; }

.section { margin-top: 16px; }
.section h2 { font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.cmd { white-space: normal; word-break: break-all; color: var(--muted); font-size: 12px; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }

.charts { display: grid; grid-template-columns: 1fr; gap: 12px; }
.chart-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.chart-box canvas { width: 100%; height: 150px; display: block; }
.ranges { display: flex; gap: 6px; margin-left: auto; }
.range {
  padding: 4px 10px; border-radius: 999px; background: var(--card2);
  border: 1px solid var(--line); font-size: 12px; cursor: pointer;
}
.range.active { background: var(--blue); color: #06121f; border-color: var(--blue); }

.footer { display: flex; gap: 6px; justify-content: center; margin-top: 18px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* --- кнопка обновления + toast --- */
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn:disabled { opacity: .55; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px);
  background: #1b2735; color: var(--text); border: 1px solid var(--line);
  padding: 9px 15px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 9999; max-width: 86vw; text-align: center;
  bottom: calc(28px + env(safe-area-inset-bottom));
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #3a1f22; border-color: #7a3b3b; }

/* --- swap + топ-процессы на карточке --- */
.swap-slot { margin-top: 2px; }

.top-mem {
  margin-top: 10px; padding-top: 9px;
  border-top: 1px solid var(--line);
}
.tm-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 6px;
}
.tm-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.tm-name {
  flex: 0 0 88px; font-size: 12px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.tm-bar {
  flex: 1 1 auto; height: 5px; background: #0d151d;
  border-radius: 3px; overflow: hidden; min-width: 20px;
}
.tm-bar > i { display: block; height: 100%; border-radius: 3px; }
.tm-val {
  flex: 0 0 62px; text-align: right; font-size: 11px;
  color: var(--muted); white-space: nowrap;
}

/* подзаголовки в детальной таблице системы */
h2.sub { padding: 12px 10px 6px; font-size: 12px; color: var(--muted);
         text-transform: uppercase; letter-spacing: .05em; }

/* ===== Список процессов: узкие строки вместо широкой таблицы ===== */
.proc-list { display: flex; flex-direction: column; gap: 2px; }

.proc-row {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.proc-row:last-child { border-bottom: 0; }
.proc-row.hot { background: rgba(239, 91, 91, .06); }

.proc-line {
  display: flex; align-items: baseline; gap: 10px; min-width: 0;
}
.proc-name {
  flex: 1 1 auto; min-width: 0; font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.proc-meta {
  flex: 0 0 auto; font-size: 12px; color: var(--muted); white-space: nowrap;
}
.proc-meta b { color: var(--text); font-weight: 600; }
.proc-meta b.hi { color: var(--red); }
.proc-meta i { font-style: normal; opacity: .45; margin: 0 4px; }

.proc-bar {
  height: 3px; margin: 6px 0 5px;
  background: #0d151d; border-radius: 2px; overflow: hidden;
}
.proc-bar > i {
  display: block; height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #2f7fd4, #4aa8ff);
}

.proc-cmd {
  font-size: 11px; line-height: 1.35; color: #6f8496;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.proc-sub { font-size: 10px; color: #55697b; margin-top: 3px; }

/* ===== Узкие строки «ключ — значение» для системных данных ===== */
.kv { display: flex; flex-direction: column; }
.kv-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px; min-width: 0;
}
.kv-row:last-child { border-bottom: 0; }
.kv-row > span {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kv-k { flex: 0 0 82px; color: var(--muted); font-size: 12px; }
.kv-v { flex: 1 1 auto; }
.kv-x { flex: 0 0 auto; color: var(--muted); font-size: 12px; max-width: 34%; }

/* ===== Переключатель сортировки процессов CPU / RAM ===== */
h2.h2row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
h2.h2row .seg {
  margin-left: 0;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  padding: 5px 11px; border-radius: 999px; cursor: pointer;
  background: var(--card2); border: 1px solid var(--line);
  color: var(--muted); text-transform: uppercase;
  transition: background .12s, color .12s, border-color .12s;
}
h2.h2row .seg:first-of-type { margin-left: auto; }
h2.h2row .seg.on {
  background: var(--blue); border-color: var(--blue); color: #06121f;
}
h2.h2row .seg:active { transform: scale(.97); }
