/* =========================================================
   微塔云 · 设备消息平台
   浅色 / 柔和阴影 / 紫蓝主色 / 大圆角
   ========================================================= */
:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --surface-2: #fafaff;
  --line: #e9e9f2;
  --line-strong: #dcdce8;
  --text: #17172a;
  --text-2: #4b4b63;
  --muted: #8a8aa3;
  --primary: #5b5bd6;
  --primary-dark: #4d4dc4;
  --primary-soft: #eeeefe;
  --violet: #7c5cf5;
  --green: #10a37f;
  --green-soft: #e7f7f2;
  --red: #e0475b;
  --red-soft: #fdecef;
  --amber-soft: #fdf5e3;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(23, 23, 42, .05);
  --shadow: 0 1px 2px rgba(23, 23, 42, .04), 0 12px 28px -18px rgba(23, 23, 42, .35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
::selection { background: #ded9ff; }

code, .mono { font-family: var(--mono); font-size: 12.5px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px; }
.text-ok { color: var(--green); }
.text-bad { color: var(--red); }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 236px;
  flex: 0 0 236px;
  height: 100vh;
  padding: 22px 16px 18px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 22px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--violet) 100%);
  box-shadow: 0 6px 14px -6px rgba(91, 91, 214, .75);
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #4b5468;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}

.nav-item svg { opacity: .8; flex: none; }
.nav-item:hover { background: #f3f4fa; color: var(--text); }
.nav-item.active { color: var(--primary-dark); background: var(--primary-soft); font-weight: 600; }
.nav-item.active svg { opacity: 1; }

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 16px;
  border-radius: 3px;
  background: var(--primary);
  transform: translateY(-50%);
}

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 4px; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  background: #e9e9fb;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-meta b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--muted); font-size: 11.5px; }

.logout {
  display: block;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.logout:hover { color: var(--red); background: var(--red-soft); text-decoration: none; }

.main { flex: 1; min-width: 0; padding: 0 34px 56px; max-width: 1360px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -34px 20px;
  padding: 26px 34px 14px;
  background: linear-gradient(var(--bg) 74%, rgba(244, 245, 250, .85) 92%, rgba(244, 245, 250, 0));
}

.topbar h1 { font-size: 22px; line-height: 1.25; }
.topbar .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .06s;
}

.btn:hover { background: var(--surface-2); border-color: #cfcfe0; color: var(--text); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(91, 91, 214, .18); }

.btn.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--violet) 100%);
  box-shadow: 0 6px 16px -10px rgba(91, 91, 214, .9);
}
.btn.primary:hover { filter: brightness(1.05); color: #fff; }

.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--red-soft); color: var(--red); }

.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; padding: 11px 14px; font-size: 14px; }

/* ---------- 卡片 ---------- */
.card {
  padding: 20px 22px;
  margin-bottom: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; font-weight: 650; }
.card-head .muted { font-size: 12px; }

.link { font-size: 13px; font-weight: 550; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }

.stat {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 18px 20px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
}

.stat::after {
  content: "";
  position: absolute;
  right: -52px;
  bottom: -62px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 92, 245, .07), transparent 68%);
  pointer-events: none;
  opacity: .6;
}

.stat:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }

.stat-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-value.accent-green { color: var(--green); }
.stat-hint { color: var(--muted); font-size: 11.5px; }

/* ---------- 提示 ---------- */
.notice {
  margin-bottom: 18px;
  padding: 12px 16px;
  border: 1px solid #f3e2b8;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  color: #7d5a12;
  font-size: 13px;
}

.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid var(--line); background: var(--surface-2); }
.banner.warn { border-color: #f3e2b8; background: var(--amber-soft); color: #7d5a12; }
.banner a { color: #6b46c1; font-weight: 600; }

.flash { margin-bottom: 16px; padding: 11px 15px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid transparent; }
.flash.ok { background: var(--green-soft); border-color: #c8ebdf; color: #0b7a5e; }
.flash.err { background: var(--red-soft); border-color: #f7cfd6; color: #a5273a; }

.new-msg-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
}
.new-msg-bar[hidden] { display: none; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }

.table th {
  padding: 9px 12px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td { padding: 11px 12px; border-bottom: 1px solid #f2f2f8; vertical-align: middle; }
.table tbody tr { transition: background .12s ease; }
.table tbody tr:hover { background: #fbfaff; }
.table tbody tr:last-child td { border-bottom: none; }
.table.compact td { padding: 9px 10px; font-size: 12.5px; }
.table.compact th { padding: 8px 10px; }

.table-card { padding: 6px 10px 8px; }
.table-card .card-head { padding: 12px 10px 2px; margin-bottom: 8px; }

.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- 标签 / 状态 ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #f2f3f9; color: var(--text-2); border: 1px solid var(--line); }
.chip.ok { background: var(--green-soft); color: #0b7a5e; border-color: #cdeee3; }
.chip.bad { background: var(--red-soft); color: #a5273a; border-color: #f7d3da; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: #f2f4f7; color: var(--muted); }
.tag.primary { background: var(--primary-soft); color: var(--primary-dark); }

.qos { display: inline-block; padding: 1px 6px; border-radius: 5px; background: #f0f1f8; color: #5d6480; font-size: 11px; font-family: var(--mono); }

.prefix-chip {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  font-size: 11.5px;
  color: #5b4bb7;
  background: #f0eeff;
  border: 1px solid #e3defb;
  border-radius: 6px;
  padding: 1px 7px;
}

.dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #c9cede; vertical-align: middle; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 163, 127, .15); }
.dot.off { background: #c9cede; }

/* ---------- 设备列表 ---------- */
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid #f2f2f8; }
.device-list li:last-child { border-bottom: none; }
.device-list b { display: block; font-size: 13px; font-weight: 600; }
.device-list small { color: var(--muted); font-size: 11.5px; }

.sysline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid #f2f2f8; }

/* ---------- 键值 ---------- */
.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed #efeff6; font-size: 13px; }
.kv li:last-child { border-bottom: none; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.copy-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; }
.copy-row code {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #3a4160;
}

/* ---------- 表单 ---------- */
input, select, textarea { font-family: inherit; font-size: 13px; color: var(--text); }

input[type="text"], input[type="password"], input[type="search"], input:not([type]), select, textarea {
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 91, 214, .13); }

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select { min-width: 190px; }
.filters input[name="topic"] { width: 230px; }
.filters input[name="q"] { width: 250px; }

.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form input[name="clientid"] { width: 250px; }
.inline-form input[name="username"] { width: 210px; }
.inline-form input[name="name"], .inline-form input[name="display_name"] { width: 180px; }
.inline-form input[name="password"] { width: 190px; }
.inline-form select[name="role"] { width: 140px; }
.inline-form select { min-width: 150px; }

.owner-form { display: flex; align-items: center; gap: 8px; }
.owner-form select { min-width: 180px; }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.hint b { color: var(--text-2); }

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

.inline-details { position: relative; display: inline-block; }
.inline-details summary { list-style: none; cursor: pointer; }
.inline-details summary::-webkit-details-marker { display: none; }

.pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  gap: 6px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.pop input { width: 150px; }

/* ---------- 前缀建议 ---------- */
.suggest { margin: 14px 0 6px; padding: 14px 16px; background: linear-gradient(180deg, #f7f6ff, #fbfaff); border: 1px dashed #d9d5f7; border-radius: var(--radius-sm); }
.suggest-title { margin-bottom: 8px; font-size: 12.5px; font-weight: 600; color: #5b4bb7; }
.suggest-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; flex-wrap: wrap; }
.suggest-row .mono { padding: 3px 8px; background: #fff; border: 1px solid #e6e2fb; border-radius: 6px; }
.suggest-row select { min-width: 160px; }

/* ---------- 空状态 ---------- */
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty.small { padding: 26px 12px; }
.empty-art { margin-bottom: 6px; font-size: 28px; color: #c9c6ef; }
.empty p { margin: 0 0 3px; color: #5b6478; font-size: 14px; font-weight: 600; }
.empty small { color: var(--muted); font-size: 12px; }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; font-size: 12.5px; color: var(--muted); }
.pager a, .pager span.cur {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-2);
}
.pager span.cur { background: var(--primary-soft); border-color: #ded9ff; color: var(--primary-dark); font-weight: 600; }

/* ---------- 消息内容 ---------- */
.payload-cell { max-width: 460px; }
.payload-cell summary {
  cursor: pointer;
  color: #4a5168;
  list-style: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  max-width: 460px;
}
.payload-cell summary::-webkit-details-marker { display: none; }

pre.payload {
  margin: 8px 0 2px;
  padding: 12px;
  background: #f7f8fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 340px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- 登录页 ---------- */
.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(900px 520px at 6% -12%, #e9e6ff 0%, transparent 60%),
    radial-gradient(720px 460px at 102% -4%, #e2f0ff 0%, transparent 55%),
    var(--bg);
}

.auth-wrap {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  width: min(980px, 100%);
  min-height: 560px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 30px 80px -40px rgba(35, 30, 90, .45);
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px;
  color: #fff;
  overflow: hidden;
  background:
    radial-gradient(520px 320px at 86% 10%, rgba(255, 255, 255, .20), transparent 60%),
    radial-gradient(420px 300px at 8% 96%, rgba(255, 255, 255, .12), transparent 60%),
    linear-gradient(150deg, #4b46c8 0%, #6a52e6 52%, #8b5cf6 100%);
}

.auth-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, .16) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: .5;
  pointer-events: none;
}

.auth-brand .head { position: relative; display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; }
.auth-brand .head .brand-mark { background: rgba(255, 255, 255, .18); box-shadow: none; }

.auth-hero { position: relative; margin-top: 44px; }
.auth-hero h2 { font-size: 26px; line-height: 1.36; letter-spacing: -.02em; }
.auth-hero p { margin: 12px 0 0; color: rgba(255, 255, 255, .84); font-size: 13.5px; line-height: 1.75; }

.auth-points { position: relative; display: flex; flex-direction: column; gap: 12px; margin: 24px 0 0; padding: 0; list-style: none; }
.auth-points li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: rgba(255, 255, 255, .92); }
.auth-points .tick { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; background: rgba(255, 255, 255, .18); font-size: 11px; }

.auth-brand .foot { position: relative; color: rgba(255, 255, 255, .62); font-size: 12px; }

.auth-pane { display: flex; align-items: center; justify-content: center; padding: 44px; }
.auth-card { width: 100%; max-width: 340px; }
.auth-card h2 { font-size: 21px; }
.auth-sub { margin: 6px 0 24px; color: var(--muted); font-size: 13px; }
.auth-card label { display: block; margin-bottom: 14px; color: #4e566e; font-size: 12.5px; font-weight: 600; }
.auth-card input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; }

.auth-error { margin: 0 0 12px; padding: 9px 12px; border: 1px solid #f7cfd6; border-radius: 8px; background: var(--red-soft); color: #a5273a; font-size: 12.5px; }
.auth-foot { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    flex: none;
    height: auto;
    padding: 14px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding-bottom: 12px; }
  .nav { flex-direction: row; gap: 6px; overflow-x: auto; }
  .nav-item { padding: 7px 11px; white-space: nowrap; }
  .nav-item.active::before { display: none; }
  .sidebar-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 12px; }
  .logout { margin-top: 0; }
  .main { padding: 0 16px 40px; }
  .topbar { margin: 0 -16px 16px; padding: 18px 16px 12px; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .filters input[name="topic"], .filters input[name="q"] { width: 100%; }
  .auth-wrap { grid-template-columns: 1fr; min-height: 0; }
  .auth-brand { display: none; }
  .auth-pane { padding: 34px 24px; }
  .auth-body { padding: 16px; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
}
