/* ==========================================================================
   主题层：在 admin.css 之上统一视觉语言
   - 只覆盖样式，不改结构；加载顺序在 admin.css 之后，同权重后者生效
   - 设计基准：圆角 10/14、柔和阴影、青色主色、12.5~14px 字号梯度
   ========================================================================== */

:root {
  /* 中性色阶 */
  --bg: #f5f7f9;
  --surface: #ffffff;
  --text: #1b2430;
  --text-soft: #3f4c5a;
  --muted: #7a8794;
  --muted-soft: #a0aab3;
  --line: #e6ebf0;
  --line-strong: #d7dee5;

  /* 表面层次：原先只有 surface 一档，卡片和内容区只能靠边框区分 */
  --surface-muted: #fbfcfc;
  --surface-sunken: #f1f4f5;

  /* 主色 */
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #e8f4f1;
  --primary-ring: rgba(15, 118, 110, 0.16);

  /* 搭配色：暖琥珀。teal 是冷色，配一个暖色做"需要留意"的强调，
     比再加一个冷色更有层次，也不会和主色抢注意力。 */
  --accent: #b45309;
  --accent-soft: #fdf2e4;

  /* 语义色：之前只有 danger，成功/提示类状态只能借用主色或灰 */
  --success: #17845c;
  --success-soft: #e8f5ef;
  --warning: #b45309;
  --warning-soft: #fdf2e4;
  --info: #2f6fb5;
  --info-soft: #eaf2fb;

  --danger: #c2413f;
  --danger-soft: #fdefee;

  /* 尺寸与投影 */
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.18);

  --sidebar: 236px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- 排版 ---------- */

.page-heading {
  padding: 4px 0 18px;
  gap: 14px;
  align-items: flex-start;
}

.page-heading h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.5px;
  line-height: 1.25;
}

.page-heading p {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
  max-width: 620px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 1.4px;
  font-weight: 600;
  color: #93a1ab;
  margin-bottom: 8px;
}

h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.1px;
}

.muted,
.field-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

/* ---------- 侧边栏 ---------- */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px 14px;
}

.brand {
  padding: 4px 8px 14px;
  gap: 10px;
  font-weight: 600;
}

.brand small {
  font-size: 9px;
  letter-spacing: 1.1px;
  color: #9aa7b1;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  box-shadow: var(--shadow-xs);
}

.workspace {
  margin: 0 4px 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #f8fafb;
  border: 1px solid var(--line);
  gap: 10px;
}

.workspace strong {
  font-size: 13px;
}

.workspace small {
  font-size: 11px;
  color: var(--muted);
}

.workspace-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 13px;
}

.nav-label {
  margin: 14px 0 6px;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #a3aeb8;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-soft);
  transition: background 0.16s ease, color 0.16s ease;
}

.nav-link .icon {
  width: 17px;
  height: 17px;
  color: #8d9aa5;
  flex-shrink: 0;
}

.nav-link:hover {
  background: #f2f6f7;
  color: var(--text);
}

.nav-link:hover .icon {
  color: var(--primary);
}

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-link.active .icon {
  color: var(--primary);
}

.sidebar-note {
  border-radius: var(--radius);
  padding: 12px;
  background: linear-gradient(160deg, #f0f7f5, #f7faf9);
  border: 1px solid #e3efeb;
}

.back-chat {
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 12px;
}

.account {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 10px;
}

.account strong {
  font-size: 12px;
}

.account small {
  font-size: 11px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  height: 60px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.breadcrumb {
  font-size: 12px;
  color: var(--muted);
  gap: 8px;
}

.breadcrumb strong {
  color: var(--text);
  font-weight: 600;
}

.breadcrumb .divider {
  color: #d3dae0;
}

.save-state {
  font-size: 12px;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 999px;
  background: #f6f8fa;
}

.save-state.dirty {
  color: #b25a1b;
  background: #fdf3e8;
}

.top-actions {
  gap: 8px;
}

/* ---------- 按钮 ---------- */

.button,
.row-actions button,
.segment button,
.icon-button {
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  border-radius: var(--radius);
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease,
    box-shadow 0.16s ease, transform 0.1s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text-soft);
  font-weight: 500;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
}

.button:hover {
  background: #f7f9fa;
  border-color: #c9d3dc;
  color: var(--text);
}

.button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.button:focus-visible,
.row-actions button:focus-visible,
.segment button:focus-visible,
.icon-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.button:disabled,
.button[disabled] {
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  opacity: 0.75;
}

/* 主按钮禁用时不要保留半透明绿，直接转中性灰，避免看成“脏色块” */
.button.primary:disabled,
.button.primary[disabled],
#saveButton:disabled,
#saveButton[disabled] {
  background: #e9edf0;
  background-image: none;
  border-color: #dfe5e9;
  color: #98a4af;
  opacity: 1;
  box-shadow: none;
}

.button.primary {
  background: linear-gradient(180deg, #12867c, var(--primary));
  border-color: #0c6b63;
  color: #fff;
  box-shadow: 0 1px 2px rgba(11, 95, 89, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.button.primary:hover {
  background: linear-gradient(180deg, #0f7c73, var(--primary-strong));
  border-color: #095349;
  color: #fff;
}

.button.small {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
  border-radius: 9px;
}

.button.danger,
.button.ghost-danger {
  color: var(--danger);
  border-color: #f0d6d5;
  background: #fff;
}

.button.danger:hover,
.button.ghost-danger:hover {
  background: var(--danger-soft);
  border-color: #e6bcba;
  color: #a5322f;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: #f2f5f7;
  color: var(--text);
}

/* 表格里的行内操作：轻量文字按钮，不再像「链接」 */
.row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions button {
  height: 28px;
  padding: 0 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: 7px;
  font-weight: 500;
}

.row-actions button:hover {
  background: #eef4f3;
  color: var(--primary-strong);
}

.row-actions button.danger {
  color: var(--danger);
}

.row-actions button.danger:hover {
  background: var(--danger-soft);
  color: #a5322f;
}

/* ---------- 表单 ---------- */

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.field .required {
  color: var(--danger);
  margin-left: 3px;
}

.field input,
.field textarea,
.field select,
.toolbar input,
.toolbar select {
  width: 100%;
  /* 与按钮同高：同一行里输入框和按钮顶边才能对齐 */
  height: var(--control-md);
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
  appearance: none;
}

.field textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  line-height: 1.7;
  resize: vertical;
}

.field select,
.toolbar select,
#sendAction {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8794' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
}

.field input:hover,
.field textarea:hover,
.field select:hover,
.toolbar input:hover,
.toolbar select:hover {
  border-color: #c6d0d9;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.toolbar input:focus,
.toolbar select:focus,
#sendAction:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.field input::placeholder,
.field textarea::placeholder,
.toolbar input::placeholder {
  color: #9aa6b2;
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  background: #f5f7f9;
  color: #98a4b0;
  box-shadow: none;
}

.form-grid {
  gap: 16px 18px;
}

/* 开关：视觉画在 .switch 上，原生 checkbox 只负责接收点击 */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
  padding-left: 48px;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
}

.switch input[type="checkbox"] {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 22px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.switch::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d7dee5;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.08);
  transition: background 0.18s ease;
}

.switch::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.22);
  transition: left 0.18s ease;
}

.switch:has(input:checked)::before {
  background: var(--primary);
}

.switch:has(input:checked)::after {
  left: 18px;
}

.switch input:focus-visible ~ span,
.switch:has(input:focus-visible)::before {
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* 动作行里的原生复选框与删除按钮 */
.cmd-row input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  margin: 0;
}

.cmd-row .button {
  height: 38px;
  border-radius: var(--radius);
}

.cmd-row .button.danger {
  border-color: #f0d6d5;
  color: var(--danger);
  background: #fff;
}

.cmd-row .button.danger:hover {
  background: var(--danger-soft);
  border-color: #e6bcba;
}

/* ---------- 工具条与分段控件 ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  justify-content: flex-start;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 180px;
  max-width: 280px;
}

#deviceSearch,
#listSearch {
  flex: 1 1 220px;
  max-width: 300px;
}

.toolbar .field-note {
  margin-left: 2px;
}

.segment {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: #f1f4f7;
  border: 1px solid var(--line);
}

.segment button {
  border: none;
  background: transparent;
  color: #64717d;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: none;
}

.segment button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}

.segment button.active {
  background: #fff;
  color: var(--primary-strong);
  box-shadow: var(--shadow-xs);
}

/* ---------- 卡片 / 面板 ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fcfdfd;
}

.panel-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.panel-body {
  padding: 18px 20px;
}

.panel-body > .toolbar {
  margin-top: -2px;
}

.panel-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fcfdfd;
}

/* ---------- 提示条 ---------- */

.notice {
  position: relative;
  padding: 11px 14px 11px 16px;
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.75;
  color: #3d4b57;
  background: #f2f8f7;
  border: 1px solid #dfeeea;
  border-radius: var(--radius);
}

.notice::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
  opacity: 0.55;
}

.notice strong {
  color: var(--text);
}

.notice.warning {
  background: #fdf6ee;
  border-color: #f3e3cd;
  color: #8a5a1f;
}

.notice.warning::before {
  background: #d98324;
}

.notice code,
.field-note code {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--primary-strong);
}

/* ---------- 表格 ---------- */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: #7c8894;
  text-align: left;
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table-wrap tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-soft);
  border-bottom: 1px solid #f1f4f6;
  vertical-align: middle;
}

.table-wrap tbody tr:last-child td {
  border-bottom: none;
}

.table-wrap tbody tr:hover td {
  background: #f9fbfb;
}

.table-wrap td strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.1px;
}

.table-wrap td small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #8b97a2;
  line-height: 1.6;
}

.table-wrap td:last-child,
.table-wrap th:last-child {
  text-align: right;
}

/* admin.css 给末列加了粘性阴影，这里会看成一条竖线，去掉 */
.table-wrap tbody td:last-child,
.table-wrap thead th:last-child {
  box-shadow: none;
}

.table-wrap td:last-child .row-actions {
  justify-content: flex-end;
}

/* 数值对齐 */
.table-wrap td .num,
.table-wrap td.num {
  font-variant-numeric: tabular-nums;
}

/* ---------- 状态胶囊 ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  background: #f1f4f7;
  color: #5b6873;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.75;
}

.pill.green {
  background: #e9f6ef;
  color: #0f7a4d;
  border-color: #d6ecdf;
}

.pill.blue {
  background: #eaf2fe;
  color: #1e5fae;
  border-color: #d8e6fb;
}

.pill.orange {
  background: #fdf2e4;
  color: #a86413;
  border-color: #f6e3ca;
}

.pill.red {
  background: var(--danger-soft);
  color: #a5322f;
  border-color: #f2d8d7;
}

.pill.purple {
  background: #f2eefd;
  color: #6842c2;
  border-color: #e5dcfb;
}

.pill.pink {
  background: #fdeef4;
  color: #a63a68;
  border-color: #f8d9e4;
}

/* ---------- 空状态 / 加载 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 44px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  text-align: center;
}

.empty .icon {
  width: 26px;
  height: 26px;
  padding: 12px;
  box-sizing: content-box;
  border-radius: 50%;
  background: #f1f5f6;
  color: #93a1ac;
  margin-bottom: 4px;
}

.empty strong {
  font-size: 13px;
  color: var(--text);
}

.empty p {
  font-size: 12px;
  color: var(--muted);
  max-width: 420px;
  line-height: 1.7;
}

.loading {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 26px 4px;
  font-size: 12px;
  color: var(--muted);
}

.spinner {
  width: 15px;
  height: 15px;
  border-width: 2px;
  border-color: #dde4ea;
  border-top-color: var(--primary);
}

/* ---------- 统计卡 ---------- */

.stats-grid {
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.stat:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: #dfe7ec;
}

.stat-head {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -1px;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}

.stat-foot {
  font-size: 11px;
  color: #9aa6b1;
}

/* ---------- 弹窗 ---------- */

dialog#editorDialog {
  border: none;
  padding: 0;
  border-radius: 16px;
  width: min(760px, calc(100vw - 40px));
  max-width: 760px;
  max-height: calc(100vh - 80px);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

dialog#editorDialog::backdrop {
  background: rgba(17, 26, 36, 0.42);
  backdrop-filter: blur(3px);
}

dialog#editorDialog[open] {
  animation: dialog-in 0.18s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

dialog#editorDialog form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  background: #fcfdfd;
}

.dialog-header h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.dialog-header .eyebrow {
  margin-bottom: 6px;
}

.dialog-body {
  padding: 18px 22px;
  overflow: auto;
  flex: 1;
  /* flex 子项默认 min-height:auto，会导致内容撑高、底部被页脚盖住，必须显式归零 */
  min-height: 0;
}

.dialog-body .panel {
  margin-bottom: 14px;
  box-shadow: none;
  border-radius: var(--radius);
}

.dialog-body .panel:last-child {
  margin-bottom: 0;
}

.dialog-body .table-wrap {
  max-height: 320px;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}

.dialog-footer > span {
  margin-right: auto;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 能力（工具）编辑器 ---------- */

/* 表单从"一堆平铺字段"改成按业务分组：每组一个标题 + 分隔线。 */
.tool-section {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.tool-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.tool-section-title {
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--primary-strong);
  letter-spacing: 0.02em;
}

.tool-section > .field + .field {
  margin-top: var(--space-3);
}

.tool-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3) var(--space-4);
}

/* 键值对表格：替代原来让人手写 JSON 的文本框 */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.4fr) auto;
  gap: var(--space-2);
  align-items: center;
}

.kv-eq {
  font-size: var(--text-sm);
  color: var(--muted-soft);
}

.kv-row input {
  width: 100%;
  min-width: 0;
}

.kv-actions {
  margin-top: var(--space-2);
}

/* 参数表：参数名 / 类型 / 说明 / 必填 / 删除 */
.param-head,
.param-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1.7fr) 64px 32px;
  gap: var(--space-2);
  align-items: center;
}

.param-head {
  padding-bottom: 6px;
  font-size: var(--text-xs);
  color: var(--muted);
}

.param-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.param-row input:not([type="checkbox"]),
.param-row select {
  width: 100%;
  min-width: 0;
}

.param-required {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
}

.param-required input {
  width: auto;
}

/* 高级设置默认收起：字段没错，但不该占运营的注意力 */
.tool-advanced {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.tool-advanced > summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-soft);
  list-style: none;
}

.tool-advanced > summary::-webkit-details-marker {
  display: none;
}

.tool-advanced > summary::before {
  content: "▸ ";
  color: var(--muted);
}

.tool-advanced[open] > summary::before {
  content: "▾ ";
}

.tool-advanced[open] > summary {
  margin-bottom: var(--space-3);
}

@media (max-width: 720px) {
  .param-head,
  .param-row {
    grid-template-columns: minmax(0, 1fr) 80px 32px;
  }

  .param-head span:nth-child(3),
  .param-head span:nth-child(4),
  .param-row .param-desc,
  .param-row .param-required {
    display: none;
  }
}

/* ---------- 自检结果 ---------- */

.self-check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.self-check-row strong {
  display: block;
  font-size: var(--text-sm);
}

.self-check-row small {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--muted);
  word-break: break-word;
}

.self-check-mark {
  flex: none;
  width: 18px;
  font-weight: var(--weight-semibold);
}

.self-check-row.is-ok .self-check-mark {
  color: var(--success);
}

.self-check-row.is-warn .self-check-mark {
  color: var(--warning);
}

.self-check-row.is-fatal {
  border-color: var(--danger);
}

.self-check-row.is-fatal .self-check-mark {
  color: var(--danger);
}

/* ---------- 提示气泡 ---------- */

.toast-area {
  gap: 8px;
  z-index: 60;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  border-radius: 11px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}

.toast.error {
  border-left-color: var(--danger);
  color: #8a2f2c;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 滚动条 ---------- */

.table-wrap::-webkit-scrollbar,
.dialog-body::-webkit-scrollbar,
main::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-wrap::-webkit-scrollbar-thumb,
.dialog-body::-webkit-scrollbar-thumb,
main::-webkit-scrollbar-thumb {
  background: #d9e0e6;
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb:hover,
.dialog-body::-webkit-scrollbar-thumb:hover {
  background: #c3ccd4;
  background-clip: content-box;
}

.table-wrap::-webkit-scrollbar-track,
.dialog-body::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- 登录页 ---------- */

.login-card {
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  padding: 30px 28px;
}

.login-card h1 {
  font-size: 22px;
  letter-spacing: -0.4px;
}

.login-card label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}

.login-card input {
  height: 40px;
  border-radius: var(--radius);
}

.login-screen {
  background: radial-gradient(1200px 600px at 50% -10%, #e8f4f1 0%, var(--bg) 55%);
}

/* ---------- 窄屏 ---------- */

/* 桌面端不显示汉堡；.icon-button 的 inline-flex 会覆盖 admin.css 的 display:none */
@media (min-width: 901px) {
  .mobile-menu {
    display: none;
  }
}

@media (max-width: 900px) {
  .page-heading h1 {
    font-size: 22px;
  }

  .topbar {
    padding: 0 14px;
  }

  .toolbar input,
  .toolbar select,
  #deviceSearch,
  #listSearch {
    max-width: 100%;
    flex: 1 1 160px;
  }

  .table-wrap thead th,
  .table-wrap tbody td {
    padding: 10px 12px;
  }

  dialog#editorDialog {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 32px);
  }
}

/* ---------- 指令集：动作卡片 ---------- */

/* 宽版弹窗：指令集这类「字段多、一条占一行」的编辑，窄弹窗会到处折行。
   放在媒体查询之后并用两层选择器，窄屏下仍受 min() 约束为满宽。 */
dialog#editorDialog.wide {
  width: min(1180px, calc(100vw - 48px));
  max-width: 1180px;
  max-height: calc(100vh - 56px);
}

dialog#editorDialog.wide form {
  max-height: calc(100vh - 56px);
}

dialog#editorDialog.wide .dialog-body {
  padding: 20px 26px;
}

dialog#editorDialog.wide .cmd-card-grid {
  grid-template-columns: 0.8fr 1fr 1.7fr;
}

dialog#editorDialog.wide .cmd-param-grid {
  grid-template-columns: 1fr 1fr 1fr;
}

/* 动作列表：一行一个动作，点开才展开输入框。动作多的包不再需要一路滚。 */
.cmd-editor {
  margin-top: 8px;
}

.cmd-editor-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.cmd-search {
  flex: 1 1 220px;
  max-width: 320px;
  height: 32px;
}

.cmd-count {
  font-size: 12px;
  color: var(--muted);
  margin-right: auto;
}

.cmd-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  /* 动作之间留足间距：展开时每张卡片是一块独立区域，不能糊成一片 */
  margin-top: var(--space-4);
  overflow: hidden;
}

.cmd-card:first-child {
  margin-top: 0;
}

/* 展开的卡片整体加重：边框、阴影、标题底色三处一起，扫一眼就能分块 */
.cmd-card.open {
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: 0 2px 10px rgba(17, 26, 36, 0.07);
}

.cmd-card-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  background: var(--surface-muted);
  cursor: pointer;
  user-select: none;
}

.cmd-card-head:hover {
  background: var(--surface-sunken);
}

.cmd-card.open .cmd-card-head {
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--line);
}

/* 展开/收起指示：16px 的 chevron，收起时转 90°。
   之前用 ▾/▸ 字符，10px 太小，看不清也点不准。 */
.cmd-caret {
  flex: none;
  width: 16px;
  height: 16px;
  color: #8b98a5;
  transition: transform 0.16s ease, color 0.16s ease;
}

.cmd-card:not(.open) .cmd-caret {
  transform: rotate(-90deg);
}

.cmd-card-head:hover .cmd-caret {
  color: var(--text-soft);
}

/* 动作序号：滚动时也能定位到第几条 */
.cmd-index {
  min-width: 20px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--muted-soft);
  font-variant-numeric: tabular-nums;
}

.cmd-card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text);
  min-width: 0;
}

.cmd-card-cmd {
  font-size: 12px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmd-card-meta {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

.cmd-card-body {
  padding: 14px 16px 16px;
}

.cmd-card-no {
  font-size: 12px;
  font-weight: 600;
  color: #75828e;
  background: #eef3f5;
  border-radius: 999px;
  padding: 2px 10px;
  letter-spacing: 0.02em;
}

.cmd-card-switch {
  margin-left: auto;
  padding-left: 44px;
  font-size: 12px;
  color: var(--text-soft);
}

.cmd-card-switch::before {
  width: 34px;
  height: 20px;
}

.cmd-card-switch::after {
  width: 16px;
  height: 16px;
}

.cmd-card-switch:has(input:checked)::after {
  left: 16px;
}

.cmd-card-grid {
  display: grid;
  /* 三个字段一行排开，卡片高度可控；窄屏再折行 */
  grid-template-columns: 0.9fr 1fr 1.5fr;
  gap: 12px 16px;
}

/* 指令集的字段用 <label class="field"><span>标题</span>…</label> 结构，
   标题是 span 而不是 label。这里只补标题样式，其余（高度、圆角、焦点环）
   全部继承全站 .field，不再维护第二套外观。 */
.field > span:first-child {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-soft);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

/* 整行字段：反例、备注这类长文本占满一整行，不挤在半栏里 */
.field-wide {
  grid-column: 1 / -1;
}

.field-warn > span:first-child {
  color: var(--accent);
}

/* 参数配置：参数由命令串里的 {名字} 决定，一个参数一行 */
.cmd-params {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.cmd-params-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cmd-params-head > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.cmd-params-hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-sunken);
  border-radius: 999px;
  padding: 1px 9px;
  font-weight: 500;
}

.cmd-params-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
}

.cmd-param-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  margin-top: 8px;
}

.cmd-param-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.cmd-param-head code {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-strong);
  /* 原来是蓝色底，和 teal 主色不同调；改为主色淡底 */
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 2px 8px;
}

.cmd-param-state {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-sunken);
  border-radius: 999px;
  padding: 2px 9px;
}

/* 设备指令页的配置体检提示：用搭配色（琥珀）区分"需要留意"，不跟主色抢注意力 */
.hw-warn {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--warning);
}

/* 反例字段的暖色标题在规范层统一处理（.field-warn > span:first-child）。 */

.cmd-param-extract {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
}

.cmd-param-extract input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.cmd-param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

@media (max-width: 900px) {
  .cmd-card-grid {
    grid-template-columns: 1fr;
  }

  .cmd-param-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   设计规范层（Design System）
   --------------------------------------------------------------------------
   上面的样式是逐年叠加的经验值：间距出现过 1–100px 共 36 种取值，
   表单写死两列、工具栏用 space-between 把按钮推到两端、表格靠 960px 硬撑。
   这一层用 4px 刻度把这些收口，统一栅格、控件、按钮与表格的行为。
   放在文件末尾，同权重时覆盖前面的散值。
   ========================================================================== */

:root {
  /* 间距刻度：全站只允许这六档，新增样式一律从这里取 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* 控件高度：输入框与按钮共用一把尺子，同一行才对得齐 */
  --control-sm: 30px;
  --control-md: 36px;

  /* 字段最小宽度：窄于它就换行，而不是把输入框压到看不见内容 */
  --field-min: 300px;
}

/* ---- 0. 排版：字体族、字号阶梯、字重与行高 ---- */

:root {
  /* 去掉 Inter：项目并没有引入 web font，声明只是回退；
     中文优先 PingFang（macOS）/ 微软雅黑（Windows），英文交给系统 UI 字体，
     避免中英混排时基线不一致。 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* 字号阶梯：11 / 12 / 13 / 14 / 16 / 18 / 20 / 26，新增样式从这里取 */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 26px;

  /* 字重只保留四个标准值，避免浏览器合成字重 */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* 行高：标题收紧、正文常规、说明放宽 */
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.7;
}

body {
  font-family: var(--font-sans);
  line-height: var(--leading-normal);
}

/* 标题：统一字重与行高；大字号收紧字距，层级才立得住 */
h1 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.4px;
}

h2 {
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  letter-spacing: -0.2px;
}

h3 {
  font-weight: var(--weight-semibold);
  line-height: 1.4;
}

/* 小标签：小字号配正字距，否则整片糊在一起 */
.eyebrow,
.nav-label {
  letter-spacing: 0.08em;
}

/* 数字统一等宽：表格金额、统计值、时间竖排才对得齐 */
.table-wrap td.num,
.table-wrap td .num,
.stat-value,
.device-time {
  font-variant-numeric: tabular-nums;
}

/* 命令串、代码用等宽字体，和正文区分开 */
code,
kbd,
.cmd-card-cmd {
  font-family: var(--font-mono);
}

/* ---- 1. 表单栅格：按可用宽度自动分列，不再写死两列 ---- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--field-min), 1fr));
  gap: var(--space-4) var(--space-5);
}

/* 长文本字段（反例、备注、说明）占满整行，不挤在半栏里 */
.form-grid > .field-wide {
  grid-column: 1 / -1;
}

/* ---- 2. 控件：占满所在栏，压缩时先缩输入框而不是换行 ---- */

.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* ---- 3. 工具栏：一律左对齐；需要靠右的操作单独包一层 .toolbar-end ---- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.toolbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---- 4. 按钮：同一行里高度与横向内边距一致 ---- */

.button {
  height: var(--control-md);
  padding: 0 var(--space-4);
}

.button.small {
  height: var(--control-sm);
  padding: 0 var(--space-3);
}

/* ---- 5. 弹窗：页脚按钮统一右对齐，正文留白统一 ---- */

.dialog-header {
  padding: var(--space-4) var(--space-5);
}

.dialog-body {
  padding: var(--space-5);
}

.dialog-footer {
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
}

/* ---- 6. 表格：小屏靠横向滚动，不再用 960px 硬撑出大片空白 ---- */

.table-wrap table {
  min-width: 640px;
}

.table-wrap thead th,
.table-wrap tbody td {
  padding: var(--space-3) var(--space-4);
}

/* ---- 7. 面板：头与内容的内边距统一 ---- */

.panel-header {
  padding: var(--space-4) var(--space-5);
}

.panel-body {
  padding: var(--space-5);
}

/* ---- 8. 专用文本框：只保留各自的排版，外观跟全站一致 ---- */

/* 规则编辑器和提示词编辑器是"大段文本"，字号、行高、等宽字体由各自决定，
   但边框、圆角、背景、焦点环必须和普通输入框用同一套视觉。 */
.rule-input,
.prompt-editor,
.device-chat-form input,
.login-card input {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.rule-input:focus,
.prompt-editor:focus,
.device-chat-form input:focus,
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* 登录页的输入框原来用绿灰边框 + 9px 圆角，和站内其它表单不是一套。
   高度也统一到控件刻度，避免"登录框比后台输入框高"的错觉。 */
.login-card input {
  height: var(--control-md);
  padding: 0 12px;
  font: inherit;
  font-size: var(--text-md);
}

/* ---- 9. 布局骨架：侧边栏 / 顶栏 / 内容区 ---- */

:root {
  /* 侧边栏宽度只在这里定义一次；admin.css 里 236/256 两处都被覆盖 */
  --sidebar: 240px;
  --topbar-h: 64px;
}

.main-shell {
  margin-left: var(--sidebar);
}

/* admin.css 里侧边栏写死过 256px，与 --sidebar 不一致，这里收回变量 */
.sidebar {
  width: var(--sidebar);
  padding: var(--space-5) var(--space-4) 0;
}

.topbar {
  height: var(--topbar-h);
  padding: 0 var(--space-6);
}

/* 内容区不再限宽居中：宽屏上左右各空 160px 是上一版最明显的问题 */
main {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: var(--space-6) var(--space-6) var(--space-8);
}

.footer {
  padding: var(--space-4) var(--space-6);
}

/* 页面标题与内容之间统一留白，标题区本身不再自带 margin */
.page-heading {
  margin-bottom: var(--space-5);
}

/* 账号区：上排身份、下排两个等宽操作，不会再出现"退出被挤下去" */
.account {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-2) var(--space-2);
  border-top: 1px solid var(--line);
  margin-top: auto;
}

.account > .avatar {
  grid-column: 1;
}

.account > .account-meta {
  grid-column: 2;
  min-width: 0;
}

.account-meta strong,
.account-meta small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.account-actions .button {
  width: 100%;
  padding: 0;
}

@media (max-width: 1024px) {
  .main-shell {
    margin-left: 0;
  }

  main {
    padding: var(--space-4);
  }

  .topbar {
    padding: 0 var(--space-4);
  }

  .footer {
    padding: var(--space-3) var(--space-4);
  }
}

/* ---- 10. 响应式：单列阈值统一在 720px ---- */

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .dialog-header,
  .dialog-body,
  .dialog-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .table-wrap table {
    min-width: 560px;
  }
}
