:root {
  --bg: #0e1216;
  --panel: #161d24;
  --panel-2: #1d262f;
  --line: #273340;
  --text: #e6edf3;
  --muted: #93a4b3;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #17222c 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

code, pre, .console { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ------------------------------- каркас ------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 246px;
  flex: 0 0 246px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: rgba(12, 16, 20, .72);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--text);
  text-decoration: none;
  font-size: 17px;
  padding: 2px 8px;
}
.logo span { color: var(--accent); }

.side-nav { display: grid; gap: 6px; }

.side-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid transparent;
  transition: background .15s, color .15s;
}
.side-btn:hover { background: #131c23; color: var(--text); }
.side-btn.active { background: #16232c; color: var(--text); border-color: var(--line); }
.side-btn.accent {
  background: linear-gradient(180deg, #1b7fa3, #166b8a);
  border-color: #1e6f8c;
  color: #f4fbff;
  font-weight: 600;
}
.side-btn.accent:hover { filter: brightness(1.08); color: #fff; }

.side-bottom { margin-top: auto; display: grid; gap: 10px; }

.side-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
  background: #131c23;
}
.side-user.active { border-color: #1e4f5f; background: #12232b; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #12303c;
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex: 0 0 32px;
}
.side-user-text { min-width: 0; }
.side-user-text b { display: block; font-size: 13.5px; }
.side-user-text small {
  display: block; color: var(--muted); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px;
}
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.content { flex: 1; min-width: 0; padding: 26px 28px 8px; display: flex; flex-direction: column; }

/* ------------------------------- элементы ----------------------------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card.narrow { max-width: 560px; }
.card h1 { margin: 0 0 12px; font-size: 22px; }
.card h2 { margin: 0 0 10px; font-size: 15px; letter-spacing: .2px; }
.card h2.tight { margin-bottom: 2px; }
.card h3 { margin: 18px 0 8px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }

.hero { padding: 10px 0 26px; }
.hero h1 { font-size: clamp(24px, 3.6vw, 34px); margin: 0 0 12px; line-height: 1.18; }
.hero p { color: var(--muted); max-width: 720px; margin: 0 0 18px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* формы */
label { display: block; margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
input[type=email], input[type=password], input[type=text] {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1319;
  color: var(--text);
  font-size: 15px;
}
input:focus { outline: 2px solid #1d4f63; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.hint code { color: var(--accent); }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid #1e6f8c;
  background: linear-gradient(180deg, #1b7fa3, #166b8a);
  color: #f4fbff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin-top: 14px;
}
.btn:hover { filter: brightness(1.08); }
.btn.small { padding: 7px 13px; font-size: 13px; margin-top: 0; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: #7f1d1d; border-color: #991b1b; color: #fee2e2; }

.inline { display: inline; }
.inline-form { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 180px; }
.inline-form .btn { margin-top: 0; }

.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.link:hover { color: var(--text); }
.link.small { font-size: 12.5px; }

/* таблицы и текст */
.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { text-align: left; padding: 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv th { color: var(--muted); font-weight: 500; width: 38%; padding-right: 14px; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }

.steps { margin: 0; padding-left: 20px; color: var(--muted); }
.steps li { margin-bottom: 8px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 16px; align-items: flex-start; }
.row.between { justify-content: space-between; align-items: center; }

.topic-pill {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 14px;
  padding: 9px 15px;
  border-radius: 999px;
  background: #0d1c22;
  border: 1px solid #1e4f5f;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

pre.code {
  background: #0b1117;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 15px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.6;
  color: #cfe3ef;
  margin: 0 0 6px;
}
pre.code code { color: var(--accent); }
code { color: var(--accent); }

.sep { border: 0; border-top: 1px solid var(--line); margin: 20px 0 0; }

/* всплывающие сообщения */
.flashes { margin-bottom: 16px; display: grid; gap: 9px; }
.flash { padding: 11px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.flash.ok { border-color: #1f4d3c; background: #10261e; color: #a7f3d0; }
.flash.error { border-color: #4d2323; background: #261010; color: #fecaca; }
.flash.warn { border-color: #4d3f1f; background: #241f10; color: #fde68a; }

/* ------------------------------ устройства ---------------------------- */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.device-card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dc-title { font-weight: 650; color: var(--text); text-decoration: none; font-size: 15px; }
.dc-title:hover { color: var(--accent); }
.dc-topic {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dc-param-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.pval { color: var(--text); font-weight: 600; }

.spark { width: 100%; height: 56px; display: block; }
.spark polyline { stroke: var(--accent); stroke-width: 1.6; }

.dc-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--muted); }
.dc-payload {
  font-family: ui-monospace, Consolas, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62%;
}

.dc-actions { display: flex; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; align-items: center; }
.dc-actions form { margin: 0; }

.pill { font-size: 11px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.pill.online { color: var(--ok); border-color: #1f4d3c; background: #10261e; }
.pill.offline { color: var(--muted); }

.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px 24px; text-align: center; }
.empty h2 { margin-top: 0; }

/* -------------------------------- графики ----------------------------- */
.chart-card h2 { margin-bottom: 2px; }
.chart {
  width: 100%;
  height: 220px;
  display: block;
  background: #0b1117;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-top: 12px;
}
.chart-line { fill: none; stroke: var(--accent); stroke-width: 1.8; }
.chart-area { fill: rgba(56, 189, 248, .12); stroke: none; }
.chart-value { font-size: 28px; font-weight: 700; color: var(--accent); line-height: 1; }
.chart-legend { display: flex; gap: 18px; color: var(--muted); font-size: 12px; margin-top: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-item { padding: 7px 12px; color: var(--muted); text-decoration: none; font-size: 13px; }
.seg-item:hover { color: var(--text); }
.seg-item.active { background: #16232c; color: var(--text); }

/* ----------------------------- сырые данные --------------------------- */
.console {
  background: #080c10;
  border: 1px solid var(--line);
  border-radius: 12px;
  height: min(62vh, 620px);
  overflow: auto;
  font-size: 12.5px;
  padding: 10px 12px;
}
.console-row {
  display: grid;
  grid-template-columns: 118px 32% 1fr;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid #10171d;
}
.console .t { color: var(--muted); }
.console .topic { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.console .payload { color: #cfe3ef; white-space: pre-wrap; word-break: break-word; }

/* -------------------------------- подвал ------------------------------ */
.foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------- адаптив ------------------------------ */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex: 0 0 auto; }
  .side-nav { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .side-bottom { margin-top: 0; }
  .content { padding: 20px 16px 8px; }
  .console-row { grid-template-columns: 96px 1fr; }
  .console .payload { grid-column: 1 / -1; }
}
