/* ============================================================================
   Search MCP Gateway · 控制台
   概念：开关板。搪瓷 L 形框（导轨 + 表头）托住一块象牙铭牌；状态落在搪瓷面上，
   阅读与编辑落在铭牌面上。账号池永远画成编号通道机架，这是全页唯一大胆的地方。

   材料层级（自上而下 = 由外向里）
     搪瓷 enamel   #16262A  带电面：导轨、表头、指示灯、状态井
     铭牌 plate    #E5E6DD  工作面：整块象牙板
     井 well       #EFEFE7  铣在铭牌上的凸起分格
     凹槽 sunken   #E8E8DF  井里的下沉槽：表格体、代码、图表

   字体：显示用 DIN 系窄体（Bahnschrift 变量字宽 90%），正文用系统无衬线，
        数字一律等宽对齐，代码才用等宽字体。零 CDN、零外部字体请求。
   ========================================================================== */

:root {
  /* 颜色 —— MASTER.md 令牌 */
  --enamel: #16262a;
  --enamel-hi: #1f353a;
  --enamel-line: #345055;
  --enamel-word: #dfe4e0;
  --enamel-mute: #8ba2a4;

  --plate: #e5e6dd;
  --plate-line: #cbcdc1;
  --well: #efefe7;
  --sunken: #e8e8df;

  --ink: #131a1c;
  --mute: #5b6a6c;
  --rule: #cbcdc1;
  --rule-soft: #d9dbd0;

  --jade: #1f8a6d;
  --amber: #b8761a;
  --fault: #b23a22;
  --signal: #1d5fb4;

  --jade-lamp: #2fb98d;
  --amber-lamp: #e0a23c;
  --fault-lamp: #d9503a;

  --jade-wash: rgba(31, 138, 109, 0.12);
  --amber-wash: rgba(184, 118, 26, 0.13);
  --fault-wash: rgba(178, 58, 34, 0.12);
  --signal-wash: rgba(29, 95, 180, 0.1);

  /* 间距 —— 24px 节奏 */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* 几何 —— 半径克制到 3px，立体感来自内嵌刻线而非阴影 */
  --r1: 2px;
  --r2: 3px;
  --r3: 4px;
  --raise: inset 0 1px 0 #fff, 0 1px 0 rgba(19, 26, 28, 0.05);
  --recess: inset 0 1px 2px rgba(19, 26, 28, 0.09);
  --drop: 0 18px 40px rgba(9, 15, 17, 0.34);

  /* 字体 */
  --font-display: "Bahnschrift SemiCondensed", "Bahnschrift", "DIN Alternate", "Roboto Condensed",
    "Arial Narrow", "Noto Sans SC", "DengXian", "Microsoft YaHei", sans-serif;
  --font-body: "Segoe UI Variable Text", "Segoe UI", "Noto Sans SC", "Source Han Sans SC", "DengXian",
    "Microsoft YaHei", ui-sans-serif, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --t: 140ms ease;

  --rail-w: 224px;
}

/* ------------------------------------------------------------------ reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--enamel);
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-stretch: 90%;
  font-weight: 600;
  letter-spacing: 0.005em;
}

p {
  margin: 0 0 var(--s2);
}

a {
  color: var(--signal);
  text-underline-offset: 2px;
}

code,
pre {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

svg.sprite {
  display: none;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 26px; height: 26px; }

/* ------------------------------------------------------------------- a11y */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  /* 绝对定位在文档上方之外：既真的移出视口，也不会在整页截图里被重复绘制 */
  position: absolute;
  top: calc(-1 * var(--s7));
  left: var(--s2);
  z-index: 40;
  padding: 8px 14px;
  border-radius: var(--r2);
  background: var(--enamel);
  color: var(--enamel-word);
  text-decoration: none;
  transition: top var(--t);
}

.skip:focus {
  position: fixed;
  top: var(--s2);
}

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.rail :focus-visible,
.strip :focus-visible,
.gate-face :focus-visible,
.save-bar :focus-visible,
.modal-head :focus-visible {
  outline-color: #7cc0ea;
}

/* ----------------------------------------------------- 搪瓷面：导轨与表头 */

.bench {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--enamel);
}

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  padding: var(--s5) var(--s4);
  color: var(--enamel-word);
  background:
    linear-gradient(180deg, var(--enamel-hi), var(--enamel) 220px),
    var(--enamel);
  border-right: 1px solid #0c1618;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.rail-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r3);
  color: var(--jade-lamp);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

/* 品牌标记的三个槽里，最下面那一格永远亮着 */
.rail-mark .icon rect:nth-of-type(2),
.rail-mark .icon rect:nth-of-type(3) {
  opacity: 0.45;
}

.rail-wordmark {
  display: grid;
  font-family: var(--font-display);
  font-stretch: 90%;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.rail-wordmark em {
  font-style: normal;
  font-weight: 400;
  color: var(--enamel-mute);
}

.rail-nav {
  display: grid;
  gap: 2px;
  align-content: start;
}

.rail-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--r2);
  font: inherit;
  font-size: 13.5px;
  color: var(--enamel-word);
  text-align: left;
  background: none;
  cursor: pointer;
  transition: background var(--t), border-color var(--t);
}

.rail-link:hover {
  background: rgba(223, 228, 224, 0.06);
}

.rail-link[aria-current="page"] {
  background: rgba(223, 228, 224, 0.1);
  border-color: var(--enamel-line);
}

/* 导轨上的指示灯：通电 = 当前分区 */
.rail-link .lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0d181a;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.rail-link[aria-current="page"] .lamp {
  background: var(--jade-lamp);
  box-shadow: 0 0 0 3px rgba(47, 185, 141, 0.16), inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.rail-count {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: var(--r1);
  font-size: 11.5px;
  text-align: center;
  color: var(--enamel-mute);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.rail-link[aria-current="page"] .rail-count {
  color: var(--enamel-word);
}

.rail-foot {
  display: grid;
  gap: var(--s3);
  margin-top: auto;
}

.lamps {
  padding: var(--s3);
  border-radius: var(--r2);
  background: #101d20;
  box-shadow: inset 0 0 0 1px var(--enamel-line), inset 0 1px 4px rgba(0, 0, 0, 0.35);
}

.lamps-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 12.5px;
}

.lamps-word {
  color: var(--enamel-word);
}

.lamps-read {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s2);
  margin: var(--s3) 0 0;
  padding-top: var(--s3);
  border-top: 1px solid var(--enamel-line);
}

.lamps-read div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.lamps-read dt {
  font-size: 11px;
  color: var(--enamel-mute);
}

.lamps-read dd {
  margin: 0;
  font-family: var(--font-display);
  font-stretch: 90%;
  font-size: 14px;
  color: var(--enamel-word);
  overflow-wrap: anywhere;
}

/* 指示灯：通电点亮，熄灭时留一个空心座 */
.lamp {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: #5b6a6c;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.lamp[data-state="ok"] {
  background: var(--jade-lamp);
  box-shadow: 0 0 0 2px rgba(47, 185, 141, 0.2), inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.lamp[data-state="warn"] {
  background: var(--amber-lamp);
  box-shadow: 0 0 0 2px rgba(224, 162, 60, 0.2), inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.lamp[data-state="bad"] {
  background: var(--fault-lamp);
  box-shadow: 0 0 0 2px rgba(217, 80, 58, 0.2), inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.lamp[data-state="unknown"] {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px #4c5f61;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5) var(--s6) var(--s4);
  color: var(--enamel-word);
  background: var(--enamel-hi);
  border-bottom: 1px solid #0c1618;
}

.strip-title {
  min-width: 0;
}

.strip h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.005em;
}

.strip-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--enamel-mute);
}

.strip-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}

/* 自动刷新：一个小型扳把开关 */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 6px 10px 6px 8px;
  border-radius: var(--r2);
  font-size: 12.5px;
  color: var(--enamel-mute);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.toggle:hover {
  color: var(--enamel-word);
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-track {
  position: relative;
  width: 28px;
  height: 15px;
  border-radius: var(--r1);
  background: #0c1719;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 1px;
  background: #6c8284;
  transition: transform var(--t), background var(--t);
}

.toggle input:checked + .toggle-track .toggle-knob {
  transform: translateX(13px);
  background: var(--jade-lamp);
}

.toggle input:checked ~ .toggle-word {
  color: var(--enamel-word);
}

.toggle input:focus-visible + .toggle-track {
  outline: 2px solid #7cc0ea;
  outline-offset: 2px;
}

/* 区间选择：表头右侧的刻度盘 */
.dial select {
  padding: 7px 26px 7px 10px;
  border: 0;
  border-radius: var(--r2);
  font: inherit;
  font-size: 12.5px;
  color: var(--enamel-word);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
  cursor: pointer;
}

.tabstrip {
  display: none;
}

/* ------------------------------------------------------------ 铭牌工作面 */

.plate {
  flex: 1;
  min-width: 0;
  padding: var(--s6);
  background: var(--plate);
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.28), inset 14px 0 24px -24px rgba(0, 0, 0, 0.5);
}

.plate > .view {
  display: grid;
  gap: var(--s5);
  align-items: start;
}

.plate :focus-visible {
  outline-color: var(--signal);
}

/* 井：铣在铭牌上的分格。所有内容都住在井里，绝不使用浮动卡片。 */
.well {
  min-width: 0;
  padding: var(--s4) var(--s5) var(--s5);
  border-radius: var(--r3);
  background: var(--well);
  box-shadow: var(--raise), 0 0 0 1px var(--plate-line);
}

.well-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--rule);
}

.well-head h3 {
  font-size: 15px;
}

.well-note {
  font-size: 12.5px;
  color: var(--mute);
}

/* 井内的纵向节奏：提示条与它后面的东西之间永远留一口气 */
.well .notice {
  margin-bottom: var(--s3);
}

.well .notice:last-child {
  margin-bottom: 0;
}

.well .field + .toolbar,
.well .toolbar + .field,
.well .toolbar + .toolbar {
  margin-top: var(--s3);
}

.endpoint {
  margin: 0 0 var(--s4);
}

.endpoint code {
  padding: 7px 12px;
  border-radius: var(--r2);
  font-size: 14px;
  color: var(--enamel-word);
  background: var(--enamel);
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.stack {
  display: grid;
  gap: 3px;
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s3);
}

.grid {
  display: grid;
  gap: var(--s5);
  align-items: start;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.spacer {
  flex: 1;
}

/* ------------------------------------------------------------- 计量表读数 */

.counters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-radius: var(--r3);
  background: var(--well);
  box-shadow: var(--raise), 0 0 0 1px var(--plate-line);
  overflow: hidden;
}

.counter {
  display: grid;
  gap: var(--s2);
  padding: var(--s4) var(--s5);
  border-left: 1px solid var(--rule-soft);
}

.counter:first-child {
  border-left: 0;
}

.counter-word {
  font-size: 12.5px;
  color: var(--mute);
}

.counter-value {
  font-family: var(--font-display);
  font-stretch: 90%;
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.005em;
}

.counter-note {
  font-size: 12px;
  color: var(--mute);
}

.gauge {
  display: flex;
  height: 6px;
  border-radius: var(--r1);
  background: #d5d7cb;
  box-shadow: var(--recess);
  overflow: hidden;
}

.gauge-fill {
  background: var(--jade);
  transition: width var(--t);
}

.gauge-fill[data-level="warn"] { background: var(--amber); }
.gauge-fill[data-level="bad"] { background: var(--fault); }

.gauge-word {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  font-size: 11.5px;
  color: var(--mute);
}

/* ----------------------------------------------------------- 标签与徽记 */

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--r1);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--enamel-word);
  background: var(--enamel);
}

.tag.soft {
  color: var(--mute);
  background: var(--sunken);
  box-shadow: inset 0 0 0 1px var(--rule);
}

.lamp-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  white-space: nowrap;
}

.lamp-label[data-state="ok"] { color: var(--jade); }
.lamp-label[data-state="warn"] { color: var(--amber); }
.lamp-label[data-state="bad"] { color: var(--fault); }
.lamp-label[data-state="unknown"] { color: var(--mute); }

.muted { color: var(--mute); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- 机架 */

.rack {
  /* 表头与槽位共用同一套列宽，否则 auto 列会把两者算成不同的栅格 */
  --rack-cols: 30px minmax(0, 1.4fr) 142px minmax(0, 0.9fr) 340px;
  /* 机架自己的容器查询：5 列排不下时换堆叠槽位，与视口宽度无关 */
  container-type: inline-size;
  border-radius: var(--r3);
  background: var(--sunken);
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
  overflow: hidden;
}

.rack-head {
  display: grid;
  grid-template-columns: var(--rack-cols);
  align-items: center;
  gap: var(--s3);
  padding: 8px var(--s4);
  font-size: 11.5px;
  color: var(--mute);
  border-bottom: 1px solid var(--rule);
  background: var(--well);
  box-shadow: var(--raise);
}

.rack-head > .num {
  text-align: right;
}

.slot {
  position: relative;
  display: grid;
  grid-template-columns: var(--rack-cols);
  align-items: center;
  gap: var(--s3);
  padding: 10px var(--s4);
  border-bottom: 1px solid var(--rule-soft);
}

.slot:last-child {
  border-bottom: 0;
}

.slot::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(22, 38, 42, 0.07), transparent 60%);
  opacity: 0;
  transition: opacity var(--t);
  pointer-events: none;
}

.slot:hover::before {
  opacity: 1;
}

.slot[data-off="true"] {
  background: repeating-linear-gradient(
    -45deg,
    transparent 0 6px,
    rgba(19, 26, 28, 0.025) 6px 12px
  );
}

.slot-no {
  display: grid;
  place-items: center;
  width: 26px;
  height: 20px;
  border-radius: var(--r1);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--enamel-word);
  background: var(--enamel);
}

.slot[data-off="true"] .slot-no {
  color: var(--enamel-mute);
  background: #26383c;
}

.slot-id {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}

.slot-name {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.slot-name strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-name span {
  font-size: 11.5px;
  color: var(--mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-meter {
  display: grid;
  gap: 4px;
}

.slot-figs {
  display: grid;
  gap: 2px;
  justify-items: end;
  font-size: 12px;
  color: var(--mute);
  text-align: right;
}

.slot-figs b {
  font-family: var(--font-display);
  font-stretch: 90%;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.slot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.slot-actions .btn {
  padding: 5px 8px;
}

/* ------------------------------------------------------------- 账本表格 */

.ledger-wrap {
  border-radius: var(--r3);
  background: var(--sunken);
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
  overflow-x: auto;
}

.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ledger th {
  padding: 9px var(--s4);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--mute);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--rule);
  background: var(--well);
  box-shadow: var(--raise);
}

.ledger th.num {
  text-align: right;
}

.ledger td {
  padding: 10px var(--s4);
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: middle;
}

.ledger tr:last-child td {
  border-bottom: 0;
}

.ledger tbody tr:hover td {
  background: rgba(22, 38, 42, 0.035);
}

.ledger .share {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.ledger .share .gauge {
  flex: 1;
  min-width: 44px;
}

/* ---------------------------------------------------------------- 图表 */

.chart-frame {
  padding: var(--s3);
  border-radius: var(--r3);
  background: var(--sunken);
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
}

.chart {
  display: block;
  width: 100%;
  height: auto;
}

/* 记录纸：细密的方格，只在图表区域内出现 */
.chart-grid line {
  stroke: #d3d5c9;
  stroke-width: 1;
}

.chart-grid line.major {
  stroke: #c2c4b7;
}

.chart .pen {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .pen-point {
  fill: var(--ink);
}

.chart .pen-point.last {
  fill: var(--jade);
  stroke: var(--well);
  stroke-width: 2;
}

.chart .axis-label {
  fill: var(--mute);
  font-family: var(--font-body);
  font-size: 10.5px;
}

.chart .bar-ok {
  fill: var(--jade);
}

.chart .bar-failed {
  fill: var(--fault);
}

.chart .bar-hit {
  fill: transparent;
}

.chart .bar-group:hover .bar-ok,
.chart .bar-group:focus .bar-ok {
  fill: #16624f;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
  margin-top: var(--s3);
  font-size: 12px;
  color: var(--mute);
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 3px;
  background: var(--ink);
}

.swatch.jade { background: var(--jade); }
.swatch.fault { background: var(--fault); }

details.fold {
  margin-top: var(--s4);
  border-top: 1px solid var(--rule-soft);
  padding-top: var(--s2);
}

details.fold > summary {
  font-size: 12.5px;
  color: var(--mute);
  cursor: pointer;
}

details.fold > summary:hover {
  color: var(--ink);
}

details.fold[open] > summary {
  margin-bottom: var(--s3);
}

/* ------------------------------------------------------------ 工具栏与段位 */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
}

.segmented {
  display: flex;
  padding: 2px;
  border-radius: var(--r2);
  background: var(--sunken);
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
}

.segmented button {
  padding: 6px 12px;
  border: 0;
  border-radius: var(--r1);
  font: inherit;
  font-size: 12.5px;
  color: var(--mute);
  background: none;
  cursor: pointer;
  transition: background var(--t), color var(--t);
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed="true"] {
  color: var(--enamel-word);
  background: var(--enamel);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  border: 0;
  border-radius: var(--r2);
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--amber-wash);
  box-shadow: inset 0 0 0 1px rgba(184, 118, 26, 0.35);
  cursor: pointer;
}

.chip:hover {
  background: rgba(184, 118, 26, 0.2);
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border: 0;
  border-radius: var(--r2);
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--well);
  box-shadow: var(--raise), 0 0 0 1px var(--rule);
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t), color var(--t);
  white-space: nowrap;
}

.btn:hover {
  background: #f6f6f0;
}

.btn:active {
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

[aria-busy="true"] {
  cursor: progress;
  opacity: 0.65;
}

/* 主操作：搪瓷键帽，按下即动作 */
.btn-key {
  color: var(--enamel-word);
  background: var(--enamel);
  box-shadow: inset 0 0 0 1px #2b4449, 0 2px 0 #0b1416;
}

.btn-key:hover {
  background: #1c3135;
}

.btn-key:active {
  transform: translateY(1px);
  box-shadow: inset 0 0 0 1px #2b4449;
}

.btn-danger {
  color: var(--fault);
  background: var(--fault-wash);
  box-shadow: inset 0 0 0 1px rgba(178, 58, 34, 0.3);
}

.btn-danger:hover {
  background: rgba(178, 58, 34, 0.2);
}

.btn-quiet {
  color: var(--enamel-word);
  background: #101d20;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.btn-quiet:hover {
  background: #17282c;
}

.btn-quiet:active {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r2);
  color: var(--mute);
  background: none;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--ink);
  background: rgba(19, 26, 28, 0.06);
}

/* ---------------------------------------------------------------- 表单 */

.field {
  display: grid;
  gap: 5px;
  margin-bottom: var(--s3);
}

.field:last-child {
  margin-bottom: 0;
}

.field > label,
.field > .label {
  font-size: 12.5px;
  color: var(--mute);
}

.field input,
.field select,
.field textarea,
.input-lamp input {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r2);
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fbfbf7;
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
  transition: box-shadow var(--t);
}

/* textarea 无论放在 .field 里还是井里，都要是同一块下沉的白槽 */
.field textarea,
.well > textarea {
  min-height: 108px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.input-lamp input:focus {
  outline: 0;
  box-shadow: var(--recess), 0 0 0 2px var(--signal);
}

.field input:disabled,
.field select:disabled {
  color: var(--mute);
  background: var(--sunken);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"] {
  box-shadow: var(--recess), 0 0 0 2px var(--fault);
}

.input-lamp {
  display: flex;
  align-items: center;
  gap: var(--s1);
  padding-right: var(--s1);
  border-radius: var(--r2);
  background: #fbfbf7;
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
}

.input-lamp input {
  background: none;
  box-shadow: none;
}

.input-lamp input:focus {
  box-shadow: none;
}

.input-lamp:focus-within {
  box-shadow: var(--recess), 0 0 0 2px var(--signal);
}

.hint {
  margin: 0;
  max-width: 68ch;
  font-size: 12px;
  line-height: 1.55;
  color: var(--mute);
}

.field-error {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12px;
  color: var(--fault);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: 5px 0;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
}

.check input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  flex: none;
  border-radius: var(--r1);
  background: #fbfbf7;
  box-shadow: var(--recess), 0 0 0 1px var(--rule);
  cursor: pointer;
}

.check input:checked {
  background: var(--jade);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.check input:checked::after {
  content: "";
  display: block;
  width: 9px;
  height: 5px;
  margin: 3px auto;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg);
}

.check code {
  font-size: 12px;
}

/* ---------------------------------------------------------------- 提示 */

.notice {
  display: flex;
  gap: var(--s3);
  max-width: 82ch;
  padding: var(--s3) var(--s4);
  border-radius: var(--r2);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--sunken);
  box-shadow: inset 0 0 0 1px var(--rule), inset 3px 0 0 var(--mute);
}

.notice .icon {
  margin-top: 2px;
  color: var(--mute);
}

.notice.info {
  background: var(--signal-wash);
  box-shadow: inset 0 0 0 1px rgba(29, 95, 180, 0.22), inset 3px 0 0 var(--signal);
}

.notice.info .icon { color: var(--signal); }

.notice.ok {
  background: var(--jade-wash);
  box-shadow: inset 0 0 0 1px rgba(31, 138, 109, 0.28), inset 3px 0 0 var(--jade);
}

.notice.ok .icon { color: var(--jade); }

.notice.warn {
  background: var(--amber-wash);
  box-shadow: inset 0 0 0 1px rgba(184, 118, 26, 0.3), inset 3px 0 0 var(--amber);
}

.notice.warn .icon { color: var(--amber); }

.notice.bad {
  background: var(--fault-wash);
  box-shadow: inset 0 0 0 1px rgba(178, 58, 34, 0.3), inset 3px 0 0 var(--fault);
}

.notice.bad .icon { color: var(--fault); }

/* ---------------------------------------------------------------- 空态 */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--s2);
  padding: var(--s6) var(--s5);
  text-align: center;
  color: var(--mute);
}

.empty .icon {
  width: 22px;
  height: 22px;
  color: var(--plate-line);
}

.empty h4 {
  font-size: 14px;
  color: var(--ink);
}

.empty p {
  max-width: 46ch;
  font-size: 12.5px;
}

.empty .btn {
  margin-top: var(--s2);
}

/* 载入占位：只做一次缓慢的呼吸，不做流光 */
.well-loading {
  min-height: 84px;
  background: var(--sunken);
  animation: breathe 1500ms ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ------------------------------------------------------------ 保存栏 */

.save-bar {
  position: sticky;
  bottom: var(--s4);
  z-index: 5;
  padding: var(--s3) var(--s4);
  border-radius: var(--r3);
  color: var(--enamel-word);
  background: var(--enamel);
  box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line);
}

.save-bar .btn {
  color: var(--enamel-word);
  background: #1d3236;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.save-bar .btn:hover {
  background: #25403f;
}

.dirty-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--amber-lamp);
}

.dirty-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber-lamp);
  box-shadow: 0 0 0 2px rgba(224, 162, 60, 0.2);
}

/* ------------------------------------------------------------ 分页/更大 */

.pager {
  padding: var(--s3) var(--s4);
  text-align: center;
  border-top: 1px solid var(--rule-soft);
}

/* ------------------------------------------------------------- 登录铭牌 */

/* 脚本没跑起来时的兜底说明：站在搪瓷面上，说清楚为什么这里是空的 */
.boot-failed {
  display: grid;
  align-content: center;
  gap: var(--s3);
  min-height: 100vh;
  max-width: 68ch;
  margin: 0 auto;
  padding: var(--s6) var(--s5);
  color: var(--enamel-word);
}

.boot-failed h1 {
  font-size: 20px;
}

.boot-failed p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--enamel-mute);
}

.boot-failed code {
  padding: 1px 5px;
  border-radius: var(--r1);
  color: var(--enamel-word);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--s5);
  background: var(--enamel);
}

.gate {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 360px);
  width: 100%;
  max-width: 720px;
  border-radius: var(--r3);
  overflow: hidden;
}

.gate-face {
  display: grid;
  align-content: start;
  gap: var(--s3);
  padding: var(--s6) var(--s5);
  border-radius: var(--r3) 0 0 var(--r3);
  color: var(--enamel-word);
  background: var(--enamel-hi);
}

.gate-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--r3);
  color: var(--jade-lamp);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
}

.gate-mark .icon rect:nth-of-type(2),
.gate-mark .icon rect:nth-of-type(3) {
  opacity: 0.45;
}

.gate-title {
  font-size: 22px;
  line-height: 1.2;
}

.gate-sub {
  max-width: 34ch;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--enamel-mute);
}

.gate-spec {
  display: grid;
  gap: 0;
  margin: var(--s5) 0 0;
  border-top: 1px solid var(--enamel-line);
}

.gate-spec div {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding: 7px 0;
  border-bottom: 1px solid var(--enamel-line);
  font-size: 12px;
}

.gate-spec dt {
  color: var(--enamel-mute);
}

.gate-spec dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--enamel-word);
}

.gate-plate {
  display: grid;
  align-content: center;
  gap: var(--s4);
  padding: var(--s6) var(--s5);
  border-radius: 0 var(--r3) var(--r3) 0;
  background: var(--well);
  box-shadow: inset 0 0 0 1px var(--plate-line);
}

.gate-head h2 {
  font-size: 17px;
}

.gate-head .hint {
  margin-top: 3px;
}

/* --------------------------------------------------------------- 弹窗 */

.modal {
  width: min(680px, calc(100vw - 2 * var(--s4)));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 0;
  border-radius: var(--r3);
  color: var(--ink);
  background: var(--well);
  box-shadow: var(--drop);
}

.modal::backdrop {
  background: rgba(9, 15, 17, 0.62);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  color: var(--enamel-word);
  background: var(--enamel);
}

.modal-head h3 {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 15px;
}

.modal-head .icon-btn {
  color: var(--enamel-mute);
}

.modal-head .icon-btn:hover {
  color: var(--enamel-word);
  background: rgba(223, 228, 224, 0.1);
}

.modal-body {
  max-height: 64vh;
  overflow: auto;
  padding: var(--s5);
}

.modal-body .field:last-child {
  margin-bottom: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  padding: var(--s3) var(--s5) var(--s4);
  border-top: 1px solid var(--rule);
}

/* 有上刻线的分块：井里或弹窗里再切一层时用 */
.ruled {
  margin-top: var(--s4);
  padding-top: var(--s3);
  border-top: 1px solid var(--rule-soft);
}

.error-summary {
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  border-radius: var(--r2);
  background: var(--fault-wash);
  box-shadow: inset 0 0 0 1px rgba(178, 58, 34, 0.3), inset 3px 0 0 var(--fault);
}

.error-summary h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--fault);
}

.error-summary ul {
  margin: var(--s2) 0 0;
  padding-left: 20px;
  font-size: 12.5px;
}

.error-summary a {
  color: var(--fault);
}

.code {
  margin: 0;
  padding: var(--s3) var(--s4);
  border-radius: var(--r2);
  font-size: 12px;
  line-height: 1.6;
  color: var(--enamel-word);
  background: #0f1c1f;
  box-shadow: inset 0 0 0 1px var(--enamel-line);
  overflow-x: auto;
  white-space: pre;
}

/* --------------------------------------------------------------- 提示条 */

.toasts {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  z-index: 30;
  display: grid;
  gap: var(--s2);
  width: min(340px, calc(100vw - 2 * var(--s4)));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r2);
  color: var(--enamel-word);
  background: var(--enamel);
  box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line), inset 3px 0 0 var(--enamel-mute);
  animation: toast-in 180ms ease-out;
}

.toast.ok { box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line), inset 3px 0 0 var(--jade-lamp); }
.toast.warn { box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line), inset 3px 0 0 var(--amber-lamp); }
.toast.error { box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line), inset 3px 0 0 var(--fault-lamp); }
.toast.info { box-shadow: var(--drop), inset 0 0 0 1px var(--enamel-line), inset 3px 0 0 #6fa8dc; }

.toast .icon {
  margin-top: 2px;
  color: var(--enamel-mute);
}

.toast.ok .icon { color: var(--jade-lamp); }
.toast.warn .icon { color: var(--amber-lamp); }
.toast.error .icon { color: var(--fault-lamp); }

.toast-body {
  flex: 1;
  font-size: 12.5px;
  line-height: 1.5;
}

.toast-close {
  border: 0;
  padding: 0;
  color: var(--enamel-mute);
  background: none;
  cursor: pointer;
}

.toast-close:hover {
  color: var(--enamel-word);
}

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

/* ------------------------------------------------------------- 自适应 */

@media (max-width: 1180px) {
  .plate {
    padding: var(--s5);
  }

  .counters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .counter:nth-child(3) {
    border-left: 0;
  }

  .counter:nth-child(n + 3) {
    border-top: 1px solid var(--rule-soft);
  }
}

@media (max-width: 960px) {
  .bench {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s3);
    padding: var(--s3) var(--s4);
    border-right: 0;
    border-bottom: 1px solid #0c1618;
  }

  .rail-nav {
    display: none;
  }

  .rail-foot {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin: 0 0 0 auto;
  }

  .lamps {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: 5px 10px;
  }

  .lamps-read {
    display: flex;
    gap: var(--s3);
    margin: 0;
    padding: 0;
    border-top: 0;
    border-left: 1px solid var(--enamel-line);
    padding-left: var(--s3);
  }

  .lamps-read div {
    grid-auto-flow: column;
    align-items: center;
    gap: 5px;
  }

  .lamps-read dd {
    font-size: 13px;
  }

  .rail-foot .btn {
    width: 32px;
    height: 30px;
    padding: 0;
    font-size: 0;
  }

  .rail-foot .btn .icon {
    width: 16px;
    height: 16px;
  }

  .strip {
    padding: var(--s4) var(--s4) var(--s3);
  }

  .strip h1 {
    font-size: 20px;
  }

  .tabstrip {
    display: flex;
    gap: var(--s1);
    padding: var(--s2) var(--s4);
    overflow-x: auto;
    background: var(--enamel-hi);
    border-bottom: 1px solid #0c1618;
    scrollbar-width: thin;
  }

  .tabstrip button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border: 0;
    border-radius: var(--r2);
    font: inherit;
    font-size: 12.5px;
    color: var(--enamel-mute);
    background: none;
    cursor: pointer;
    white-space: nowrap;
  }

  .tabstrip button[aria-current="page"] {
    color: var(--enamel-word);
    background: rgba(223, 228, 224, 0.1);
  }

  .grid.cols-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* 5 列机架约需 820px。概览页把机架放在半幅井里，靠的是这条容器查询而不是视口断点。 */
@container (max-width: 860px) {
  .slot {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    row-gap: var(--s2);
  }

  .slot-meter {
    grid-column: 2 / -1;
  }

  .slot-figs {
    grid-column: 3;
    grid-row: 1;
  }

  .slot-actions {
    grid-column: 2 / -1;
    justify-content: flex-start;
  }

  .rack-head {
    display: none;
  }
}

@media (max-width: 720px) {
  .plate {
    padding: var(--s3);
  }

  .well {
    padding: var(--s3) var(--s3) var(--s4);
  }

  .counters {
    grid-template-columns: minmax(0, 1fr);
  }

  .counter,
  .counter:nth-child(3) {
    border-left: 0;
  }

  .counter:nth-child(n + 2) {
    border-top: 1px solid var(--rule-soft);
  }

  /* 窄屏下账本表转成两列的行卡片：首格（身份/时间）独占一行，其余成对排布 */
  .ledger thead {
    display: none;
  }

  .ledger,
  .ledger tbody,
  .ledger tr,
  .ledger td {
    display: block;
    width: 100%;
  }

  .ledger tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px var(--s3);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--rule);
  }

  .ledger td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: 2px 0;
    border-bottom: 0;
    text-align: left;
  }

  .ledger td:first-child {
    grid-column: 1 / -1;
  }

  .ledger td::before {
    content: attr(data-label);
    flex: none;
    font-size: 11.5px;
    color: var(--mute);
  }

  .ledger td.num {
    text-align: right;
  }

  .toasts {
    right: var(--s3);
    left: var(--s3);
    bottom: var(--s3);
    width: auto;
  }

  .gate {
    grid-template-columns: minmax(0, 1fr);
  }

  .gate-face {
    border-radius: var(--r3) var(--r3) 0 0;
    padding: var(--s5) var(--s4);
  }

  .gate-plate {
    border-radius: 0 0 var(--r3) var(--r3);
    padding: var(--s5) var(--s4);
  }

  .gate-spec {
    display: none;
  }

  .toasts {
    max-width: none;
  }
}

@media (max-width: 520px) {
  .strip-controls .toggle-word,
  .strip-controls .btn-word {
    display: none;
  }

  .strip-controls .toggle {
    padding: 6px 8px;
  }

  .modal-body {
    padding: var(--s4);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
