/* ==========================================================================
   工具箱 · 设计令牌与基础布局
   ========================================================================== */
:root {
  --bg: #f5f6f9;
  --bg-soft: #eceef4;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --line: #e4e7ee;
  --line-strong: #d3d8e2;
  --text: #15171c;
  --text-soft: #4b5261;
  --muted: #767e91;
  --accent: #4338ca;
  --accent-hover: #3730b3;
  --accent-soft: rgba(67, 56, 202, 0.09);
  --accent-line: rgba(67, 56, 202, 0.24);
  --ok: #0f9d58;
  --warn: #b45309;
  --danger: #d13b3b;
  --danger-soft: rgba(209, 59, 59, 0.08);
  --code-bg: #f8f9fc;
  --shadow-sm:
    0 1px 2px rgba(18, 22, 33, 0.05), 0 1px 1px rgba(18, 22, 33, 0.04);
  --shadow-md:
    0 10px 30px -12px rgba(18, 22, 33, 0.18), 0 2px 6px rgba(18, 22, 33, 0.05);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --mono:
    ui-monospace, "Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas,
    "Liberation Mono", monospace;
  --sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --sidebar-w: 290px;
  --rail-w: 66px; /* 桌面端折叠后的图标条宽度 */
  --gap: 16px;
}

[data-theme="dark"] {
  --bg: #0c0e12;
  --bg-soft: #12151b;
  --surface: #14171e;
  --surface-2: #171b23;
  --line: #232833;
  --line-strong: #2e3543;
  --text: #e7eaf0;
  --text-soft: #b3bac7;
  --muted: #828b9c;
  --accent: #8b93ff;
  --accent-hover: #a3aaff;
  --accent-soft: rgba(139, 147, 255, 0.14);
  --accent-line: rgba(139, 147, 255, 0.32);
  --ok: #3ddc97;
  --warn: #f0b35c;
  --danger: #ff7b7b;
  --danger-soft: rgba(255, 123, 123, 0.12);
  --code-bg: #101318;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 16px 40px -18px rgba(0, 0, 0, 0.7);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.62;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

::selection {
  background: var(--accent-soft);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}

/* ---------- 侧栏 ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 14px 14px;
  overflow: hidden; /* 折叠动画期间裁掉内容，避免文字被挤成竖排 */
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 4px 2px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(150deg, var(--accent), #7c4dff 70%, #2b8ef2);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 19px;
  height: 19px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}
.brand-text strong {
  font-size: 15.5px;
  letter-spacing: 0.2px;
}
.brand-text span {
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--mono);
}

/* 折叠/展开按钮，桌面与窄屏都要可见：窄屏点击等价于关闭抽屉。
   选择器带 button 前缀，否则会被后面的 .icon-btn { display: grid } 覆盖 */
button.sidebar-close {
  margin-left: auto;
}
.sidebar-close svg {
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  transition:
    border-color 0.16s,
    box-shadow 0.16s;
}

.search:focus-within {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search svg {
  width: 15px;
  height: 15px;
  flex: none;
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font-size: 13.5px;
  color: var(--text);
}
.search input::-webkit-search-cancel-button {
  display: none;
}
.search kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--muted);
}

/* 取色字段：系统取色框 + 文本框并排 */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-color .count {
  display: none;
}
input.picker {
  width: 46px;
  height: 38px;
  flex: none;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}
input.picker::-webkit-color-swatch-wrapper {
  padding: 0;
}
input.picker::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}
input.picker:hover {
  border-color: var(--line-strong);
}

.nav {
  flex: 1;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px 4px;
}
.nav::-webkit-scrollbar {
  width: 8px;
}
.nav::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
}

.nav-group + .nav-group {
  margin-top: 16px;
}
.nav-group h3 {
  margin: 0 0 5px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text-soft);
  cursor: pointer;
  text-align: left;
  font-size: 13.6px;
  transition:
    background 0.14s,
    color 0.14s;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex: none;
  opacity: 0.78;
}
.nav-item:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active svg {
  opacity: 1;
}
.nav-item small {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}
.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-empty {
  padding: 14px 10px;
  color: var(--muted);
  font-size: 13px;
}

.side-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.status span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  box-shadow: 0 0 0 3px rgba(118, 126, 145, 0.16);
}
.status[data-state="ok"] {
  color: var(--ok);
  border-color: rgba(15, 157, 88, 0.28);
}
.status[data-state="ok"] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.16);
}
.status[data-state="fail"] {
  color: var(--danger);
  border-color: rgba(209, 59, 59, 0.3);
}
.status[data-state="fail"] .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}
.status[data-state="checking"] {
  color: var(--accent);
  border-color: var(--accent-line);
}
.status[data-state="checking"] .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.32;
  }
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  transition:
    background 0.14s,
    color 0.14s,
    border-color 0.14s,
    transform 0.14s;
}
.icon-btn svg {
  width: 17px;
  height: 17px;
}
.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--line-strong);
}
.icon-btn:active {
  transform: translateY(1px);
}

/* 键盘焦点统一可见，鼠标点击不出现描边 */
.nav-item:focus-visible,
.tab:focus-visible,
.btn:focus-visible,
.text-btn:focus-visible,
.icon-btn:focus-visible,
.status:focus-visible,
.history-row .text-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* 极淡的双色光晕，让内容卡片从背景上浮起来（不参与布局，纯装饰） */
  background-image:
    radial-gradient(
      1100px 460px at 84% -8%,
      var(--accent-soft),
      transparent 68%
    ),
    radial-gradient(900px 420px at 4% 4%, var(--bg-soft), transparent 72%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
}

button.menu-btn {
  display: none;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.8px;
  color: var(--muted);
  min-width: 0;
}
.crumbs b {
  color: var(--text);
  font-weight: 600;
  font-size: 13.6px;
}
.crumbs i {
  font-style: normal;
  opacity: 0.55;
}
.crumbs code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}

.clock {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.content {
  padding: 26px 26px 8px;
  max-width: 1180px;
  width: 100%;
}

.tool-head {
  margin-bottom: 18px;
  animation: rise 0.26s ease both;
}
.tool-head h1 {
  margin: 0 0 6px;
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.tool-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13.8px;
  max-width: 74ch;
  text-wrap: pretty;
}

/* ---------- 面板 ---------- */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  animation: rise 0.3s ease both;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  width: fit-content;
  max-width: 100%;
}
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 13px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-soft);
  font-size: 13.2px;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  transition:
    background 0.14s,
    color 0.14s,
    box-shadow 0.14s;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.grid {
  display: grid;
  gap: var(--gap);
}
.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}
.field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.4px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.01em;
}
.field-label small {
  font-weight: 400;
  color: var(--muted);
  font-size: 11.5px;
}
.field-label .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

textarea,
.input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--code-bg);
  padding: 11px 13px;
  font-family: var(--mono);
  font-size: 13.2px;
  line-height: 1.66;
  color: var(--text);
  outline: none;
  transition:
    border-color 0.16s,
    box-shadow 0.16s,
    background 0.16s;
}
textarea {
  min-height: 158px;
  resize: vertical;
  tab-size: 4;
}
textarea:focus,
.input:focus,
select:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}
textarea::placeholder,
.input::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}
.input,
select {
  font-family: var(--sans);
  padding: 8px 11px;
  min-height: 36px;
  background: var(--surface);
}
textarea.out {
  background: var(--surface-2);
  min-height: 158px;
  cursor: text;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 16px,
    calc(100% - 11px) 16px;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px dashed var(--line);
}
.option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.8px;
  color: var(--text-soft);
}
.option > span {
  white-space: nowrap;
}
.option .input,
.option select {
  min-width: 92px;
  width: auto;
}
.option .input.num {
  width: 92px;
}

.check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  padding: 5px 11px 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12.6px;
  color: var(--text-soft);
  transition:
    border-color 0.14s,
    background 0.14s,
    color 0.14s;
}
.check input {
  appearance: none;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.check input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.check input:checked::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 1.8px solid #fff;
  border-bottom: 1.8px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
}
.check:has(input:checked) {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: 18px;
}
.hint {
  margin-left: auto;
  font-size: 11.8px;
  color: var(--muted);
}
.hint kbd {
  font-family: var(--mono);
  font-size: 10.8px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.2px;
  font-weight: 550;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    background 0.14s,
    border-color 0.14s,
    color 0.14s,
    transform 0.1s,
    box-shadow 0.14s;
}
.btn svg {
  width: 15px;
  height: 15px;
  flex: none;
  display: block;
}

/* 文字用真实元素承载并归一行盒，避免中文基线造成的视觉偏移 */
.btn .btn-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn:hover {
  border-color: var(--muted);
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent);
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
/* 危险操作：与其它 .btn 同尺寸同描边，只用 danger 色调区分 */
.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, var(--line-strong));
}
.btn.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}
.btn:disabled {
  opacity: 0.62;
  cursor: progress;
}
/* 忙碌态：让按钮内的图标转起来（图标是按钮的第一个 svg 子元素） */
.btn.busy > svg {
  animation: spin 0.8s linear infinite;
}
/* 复制成功后短暂高亮，给出就地反馈 */
.btn .btn-label.done,
.text-btn.done {
  color: var(--ok);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12.4px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}
.text-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- 输出块 ---------- */
.outputs {
  display: grid;
  gap: 16px;
}

/*
 * 面板内的结果宿主：间距写死在宿主自身，
 * 不依赖 .toolbar + .outputs 这类兄弟选择器，结构变化也不会失效
 */
.results {
  display: grid;
  gap: 16px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}

.note.placeholder {
  padding: 15px 16px;
  border-style: dashed;
  border-color: var(--line-strong);
  background: none;
  color: var(--muted);
  font-size: 13.2px;
}
.note.placeholder svg {
  margin-top: 1px;
  opacity: 0.8;
}
.out {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  animation: rise 0.22s ease both;
}
.out-head .tag {
  white-space: nowrap;
}
.out-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.out-head h3 {
  margin: 0;
  font-size: 12.4px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.out-head .tag {
  font-family: var(--mono);
  font-size: 10.8px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}
.out-head .spacer {
  margin-left: auto;
}
/* 卡片头部的按钮更紧凑一档，避免压过标题，但仍保持同样的居中规则 */
.out-head .btn {
  padding: 5px 11px;
  font-size: 12.6px;
}
.out-body {
  padding: 12px;
}
.out-body > textarea {
  border: 0;
  background: none;
  padding: 0;
  box-shadow: none;
}
.out-body > textarea:focus {
  box-shadow: none;
}

pre.code {
  margin: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  max-height: 460px;
  overflow: auto;
}
pre.code.clip {
  max-height: 190px;
}
pre.code {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
pre.code::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
pre.code::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
}
pre.code::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
pre.code::-webkit-scrollbar-track {
  background: transparent;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.6px;
}
table.data th,
table.data td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--surface);
  position: sticky;
  top: 0;
}
table.data td {
  font-family: var(--mono);
  word-break: break-all;
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data tbody tr:hover td {
  background: var(--accent-soft);
}
table.data td.k {
  font-family: var(--sans);
  color: var(--text-soft);
  width: 132px;
}
table.data td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}
/* 色板 */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.swatch {
  width: 118px;
  padding: 0 0 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 0.14s,
    box-shadow 0.14s,
    transform 0.14s;
}
.swatch:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.swatch.copied {
  border-color: var(--ok);
}
.swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.swatch-chip {
  display: block;
  height: 52px;
  border-bottom: 1px solid var(--line);
}
.swatch-hex {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 12.2px;
  color: var(--text);
}
.swatch-label {
  display: block;
  font-size: 11.6px;
  color: var(--text-soft);
}
.swatch-sub {
  display: block;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 10.6px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  scrollbar-width: thin;
}
.table-wrap::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
}

dl.kv {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 0;
  margin: 0;
  font-size: 13px;
}
dl.kv dt {
  padding: 7px 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 12.4px;
}
dl.kv dd {
  margin: 0;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12.6px;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 8px;
}
dl.kv dt:last-of-type,
dl.kv dd:last-of-type {
  border-bottom: 0;
}
dl.kv dd.plain {
  font-family: var(--sans);
  font-size: 13px;
}
dl.kv dd .inline-copy {
  opacity: 0;
}
dl.kv dd:hover .inline-copy {
  opacity: 1;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.2px;
  font-weight: 600;
  font-family: var(--sans);
}
.badge.ok {
  background: rgba(15, 157, 88, 0.12);
  color: var(--ok);
}
.badge.bad {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge.mute {
  background: var(--bg-soft);
  color: var(--muted);
}

.note {
  display: flex;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12.8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-soft);
}
.note svg {
  width: 15px;
  height: 15px;
  flex: none;
  margin-top: 2px;
}
.note.warn {
  border-color: rgba(180, 83, 9, 0.3);
  background: rgba(180, 83, 9, 0.08);
  color: var(--warn);
}
.note.err {
  border-color: rgba(209, 59, 59, 0.32);
  background: var(--danger-soft);
  color: var(--danger);
}
.note pre {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 11.8px;
  white-space: pre-wrap;
  word-break: break-all;
  color: inherit;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-family: var(--mono);
  font-size: 11.4px;
  color: var(--muted);
}

.image-preview {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.qr-preview {
  display: block;
  max-width: min(100%, 520px);
  max-height: 520px;
  width: auto;
  height: auto;
  image-rendering: pixelated;
  background: #fff;
}
.out-head a.btn {
  text-decoration: none;
}

/* ---------- 历史 ---------- */
.history {
  margin: 22px 26px 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.history-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
}
.history-head h2 {
  margin: 0;
  font-size: 13.4px;
  font-weight: 620;
}
.history-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.history-body {
  border-top: 1px solid var(--line);
  padding: 6px 0;
}
.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  font-size: 12.6px;
}
.history-row:hover {
  background: var(--surface-2);
}
.history-row .h-tool {
  font-weight: 600;
  color: var(--text);
  flex: none;
  width: 132px;
}
.history-row .h-io {
  font-family: var(--mono);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.history-row .h-io b {
  color: var(--text-soft);
  font-weight: 500;
}
.history-row time {
  font-family: var(--mono);
  font-size: 11.4px;
  color: var(--muted);
  flex: none;
}
.history-empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- WebSocket 调试面板 ---------- */
/*
 * 这个面板不走通用的「填表 → 执行 → 结果块」流程，样式自成一套，
 * 但颜色、圆角、字号全部沿用同一批设计令牌，深浅色主题自动跟随。
 */
.panel-host {
  animation: rise 0.3s ease both;
}

.ws-panel {
  display: flex;
  flex-direction: column;
}
.ws-status {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ws-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
}
.ws-bar-tight {
  margin-top: 10px;
}
.ws-bar .spacer,
.ws-head .spacer {
  margin-left: auto;
}

/* 连接状态灯：与侧栏后端状态灯同一套视觉语言 */
.ws-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 12.6px;
  line-height: 1;
  white-space: nowrap;
}
.ws-state .dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(118, 126, 145, 0.16);
}
.ws-state[data-state="open"] {
  color: var(--ok);
  border-color: rgba(15, 157, 88, 0.32);
  background: rgba(15, 157, 88, 0.08);
}
.ws-state[data-state="open"] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.16);
}
.ws-state[data-state="connecting"],
.ws-state[data-state="closing"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.ws-state[data-state="connecting"] .dot,
.ws-state[data-state="closing"] .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.2s ease-in-out infinite;
}
.ws-state[data-state="error"] {
  color: var(--danger);
  border-color: rgba(209, 59, 59, 0.34);
  background: var(--danger-soft);
}
.ws-state[data-state="error"] .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.ws-target {
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  font-family: var(--mono);
  font-size: 11.6px;
  color: var(--muted);
}
.ws-stats b {
  color: var(--text-soft);
  font-weight: 600;
}

.ws-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
}
.ws-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.ws-head h2 {
  margin: 0;
  font-size: 12.8px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--text);
}
.ws-head small {
  color: var(--muted);
  font-size: 11.6px;
}
.ws-head .btn {
  padding: 5px 11px;
  font-size: 12.6px;
}

.ws-url {
  flex: 1;
  min-width: 260px;
  font-family: var(--mono);
}
.ws-bar select {
  width: auto;
  min-width: 132px;
}
.ws-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.6px;
  color: var(--text-soft);
}
.ws-inline .input,
.ws-inline select {
  width: auto;
  min-width: 88px;
}
.ws-inline .input.num {
  width: 92px;
}
.ws-heartbeat {
  min-width: 200px;
  flex: 1;
  font-family: var(--mono);
}
.ws-note {
  margin: 10px 0 0;
  font-size: 11.8px;
  line-height: 1.6;
  color: var(--muted);
}
.ws-hint {
  display: block;
  margin-top: 7px;
  font-size: 11.6px;
  color: var(--muted);
}

/* 预设端点与地址历史：都做成药丸，一眼能点 */
.ws-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
}
.ws-presets .btn {
  padding: 4px 10px;
  font-size: 12.2px;
  border-radius: 999px;
}
.ws-presets .btn svg {
  width: 13px;
  height: 13px;
}
.ws-hist-label {
  font-size: 11.6px;
  color: var(--muted);
}
.ws-chip-url {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
}
.ws-chip-main {
  max-width: 320px;
  padding: 4px 4px 4px 11px;
  border: 0;
  background: none;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 11.8px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.ws-chip-main:hover {
  color: var(--accent);
}
.ws-chip-x {
  padding: 4px 9px 4px 5px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
}
.ws-chip-x:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.ws-message {
  min-height: 96px;
  margin-top: 12px;
}
.ws-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px dashed var(--line);
}
.ws-burst {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.2px;
  color: var(--muted);
}
.ws-burst i {
  font-style: normal;
}
.ws-burst .input.num {
  width: 78px;
}

.ws-filters {
  margin: 0;
  padding: 3px;
}
.ws-keyword {
  flex: 1;
  width: auto;
  min-width: 150px;
  max-width: 240px;
}
.ws-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11.6px;
  color: var(--muted);
  white-space: nowrap;
}

/* 逐帧日志：等宽字体 + 四列网格（方向 / 时间 / 大小 / 内容） */
.ws-log {
  margin-top: 12px;
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--code-bg);
  scrollbar-width: thin;
}
.ws-log::-webkit-scrollbar {
  width: 9px;
}
.ws-log::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
}
.ws-row {
  display: grid;
  grid-template-columns: 52px 96px 80px minmax(0, 1fr);
  gap: 4px 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12.4px;
  cursor: pointer;
}
.ws-row:last-child {
  border-bottom: 0;
}
.ws-row:hover {
  background: var(--accent-soft);
}
.ws-row .d {
  font-weight: 700;
  white-space: nowrap;
}
.ws-row .t {
  color: var(--muted);
  font-size: 11.4px;
  white-space: nowrap;
}
.ws-row .s {
  color: var(--muted);
  font-size: 11.4px;
  text-align: right;
  white-space: nowrap;
}
.ws-row .m {
  min-width: 0;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
}
.ws-row .m.clip {
  max-height: 118px;
  overflow: hidden;
}
.ws-row[data-dir="in"] .d {
  color: var(--ok);
}
.ws-row[data-dir="out"] .d {
  color: var(--accent);
}
.ws-row[data-dir="sys"] {
  background: color-mix(in srgb, var(--bg-soft) 55%, transparent);
}
.ws-row[data-dir="sys"] .d,
.ws-row[data-dir="sys"] .m {
  color: var(--muted);
}
.ws-row[data-kind="binary"] .m {
  color: var(--warn);
}
.ws-hex {
  font-size: 11.8px;
}
.ws-b64 {
  margin-top: 3px;
  font-size: 11.2px;
  color: var(--muted);
  word-break: break-all;
}
.ws-empty {
  margin: 0;
  padding: 20px 14px;
  color: var(--muted);
  font-size: 12.8px;
  text-align: center;
}

/* 速查表默认折叠，不抢主流程的视线 */
.ws-ref {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.ws-ref summary {
  color: var(--text-soft);
  font-size: 12.8px;
  font-weight: 600;
  cursor: pointer;
}
.ws-ref summary:hover {
  color: var(--accent);
}
.ws-ref-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 14px;
}
.ws-ref-body h3 {
  margin: 0 0 8px;
  font-size: 12.4px;
  font-weight: 650;
}
.ws-ref .table-wrap {
  max-height: 300px;
}

@media (max-width: 1080px) {
  .ws-ref-body {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 900px) {
  .ws-row {
    grid-template-columns: 46px 84px minmax(0, 1fr);
  }
  .ws-row .s {
    grid-column: 3;
    text-align: left;
  }
  .ws-url {
    min-width: 100%;
  }
}
@media (max-width: 560px) {
  .ws-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .ws-row .s {
    grid-column: 1;
  }
  .ws-keyword {
    max-width: none;
  }
  .ws-chip-main {
    max-width: 190px;
  }
}
/* ---------- 提示气泡 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 12.8px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s,
    transform 0.18s;
  z-index: 60;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  z-index: 25;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 桌面端折叠成图标条 ---------- */
/* 只在桌面宽度生效：窄屏仍然走抽屉，两套状态互不干扰 */
@media (min-width: 901px) {
  .app.sidebar-collapsed {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }
  .app.sidebar-collapsed .sidebar {
    padding: 18px 8px 14px;
  }
  .app.sidebar-collapsed .brand {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-bottom: 2px;
  }
  .app.sidebar-collapsed .brand-text {
    display: none;
  }
  .app.sidebar-collapsed button.sidebar-close {
    margin-left: 0;
  }
  .app.sidebar-collapsed .sidebar-close svg {
    transform: rotate(180deg);
  }
  .app.sidebar-collapsed .search {
    display: none;
  }
  .app.sidebar-collapsed .nav {
    margin: 0;
    padding: 0 2px 4px;
  }
  .app.sidebar-collapsed .nav-group h3,
  .app.sidebar-collapsed .nav-label,
  .app.sidebar-collapsed .nav-item small,
  .app.sidebar-collapsed .nav-empty {
    display: none;
  }
  .app.sidebar-collapsed .nav-group + .nav-group {
    margin-top: 10px;
  }
  .app.sidebar-collapsed .nav-item {
    justify-content: center;
    gap: 0;
    padding: 8px 0;
  }
  .app.sidebar-collapsed .nav-item svg {
    width: 18px;
    height: 18px;
    opacity: 0.85;
  }
  .app.sidebar-collapsed .side-foot {
    flex-direction: column;
    gap: 10px;
  }
  .app.sidebar-collapsed .status {
    flex: none;
    width: 34px;
    height: 34px;
    padding: 0;
  }
  .app.sidebar-collapsed .status span {
    display: none;
  }
}

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

@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 84vw);
    transform: translateX(-102%);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.3, 1);
    box-shadow: var(--shadow-md);
  }
  .sidebar.open {
    transform: none;
  }
  /* 折叠样式整体收敛在 min-width: 901px 内，窄屏只负责把汉堡键放出来 */
  button.menu-btn {
    display: grid;
  }
  .content {
    padding: 20px 16px 6px;
  }
  .history {
    margin: 18px 16px 26px;
  }
  .topbar {
    padding: 0 16px;
  }
  .clock {
    display: none;
  }
}

@media (max-width: 560px) {
  .tool-head h1 {
    font-size: 21px;
  }
  .panel {
    padding: 15px;
    border-radius: 14px;
  }
  dl.kv {
    grid-template-columns: minmax(0, 1fr);
  }
  dl.kv dt {
    padding-bottom: 0;
    border-bottom: 0;
  }
  .history-row .h-tool {
    width: auto;
  }
  .history-row {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn.busy > svg,
  .status[data-state="checking"] .dot {
    animation: none !important;
  }
}
