/* 深色主题：配色与参考图一致 */
:root {
  --bg: #0b1220;
  --panel: #0e1726;
  --field: #111d30;
  --row-alt: #0f1a2b;
  --hover: #16233a;
  --line: #1c2a40;
  --text: #e8eef5;
  --muted: #8b98a9;
  --accent: #06b6d4;
  --accent-hover: #22d3ee;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --dot-gray: #9aa7b8;
  --placeholder: #5c6b80;
}

/* 亮色主题：同名变量覆盖 */
body.light {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --field: #edf1f7;
  --row-alt: #f7f9fc;
  --hover: #e4eaf3;
  --line: #d5dde8;
  --text: #1b2534;
  --muted: #5a677d;
  --accent: #0e7490;
  --accent-hover: #155e75;
  --green: #047857;
  --red: #dc2626;
  --yellow: #b45309;
  --dot-gray: #94a3b8;
  --placeholder: #94a3b8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- 菜单栏 ---------- */
.tabs-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  align-self: center;
  padding-bottom: 5px;
}

/* ---------- 两级菜单 ---------- */
.tab-menu { position: relative; display: flex; }
.tab-parent { display: inline-flex; align-items: center; gap: 5px; }
.tab-parent .caret { font-size: 10px; opacity: .7; }
.tab-menu.current > .tab-parent {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0 0 9px 9px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .28);
  z-index: 60;
  padding: 4px 0;
}
.tab-menu:hover .tab-dropdown,
.tab-menu.open .tab-dropdown { display: block; }
.dd-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.dd-item:hover { background: var(--hover); color: var(--text); }
.dd-item.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--row-alt);
}

/* ---------- 页面导航（面包屑） ---------- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 0;
  font-size: 14px;
  color: var(--muted);
}
.crumb-link { color: var(--muted); text-decoration: none; }
.crumb-link:hover { color: var(--text); }
.crumb-sep { opacity: .55; }
.crumb-here { color: var(--text); font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--hover); }
.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #04303a;
  font-weight: 700;
}
.btn.accent:hover { background: var(--accent-hover); }
.btn.accent:disabled { background: #155e6b; border-color: #155e6b; color: #9fc9d2; cursor: wait; }
.btn.ghost { background: transparent; }

/* ---------- 布局 ---------- */
.layout {
  display: flex;
  gap: 14px;
  padding: 14px;
  flex: 1;
  min-height: 0;
}

/* 左侧栏 */
.sidebar {
  width: 290px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.panel-title { color: var(--muted); font-weight: 600; letter-spacing: 1px; font-size: 13px; }

.part-list {
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.part-list li {
  padding: 8px 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13.5px;
  cursor: pointer;
  border-bottom: 1px solid rgba(28, 42, 64, .45);
}
.part-list li:hover { background: var(--hover); }
.part-list li.selected { background: var(--hover); }

.text-input {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  width: 100%;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--placeholder); }

.sidebar-btns { display: flex; gap: 8px; }
.sidebar-btns .accent { flex: 1; }

/* 右侧结果区 */
.results { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.stats-row { display: flex; align-items: center; gap: 18px; }
.stat { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat b { color: var(--text); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.gray { background: var(--dot-gray); }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--field);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .5px;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th.num { text-align: center; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th .arrow { font-size: 10px; }
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(28, 42, 64, .45);
  font-size: 13.5px;
  white-space: nowrap;
}
tbody tr:hover { background: var(--hover); }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:nth-child(even):hover { background: var(--hover); }
td.part { font-family: Consolas, "Courier New", monospace; font-weight: 600; }
td.num { text-align: center; }
td.stock { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
td.stock.ok { color: var(--green); }
td.stock.zero { color: var(--red); }
td.stock.low { color: var(--yellow); }
td.stock.err { color: var(--red); }
td.stock.pending { color: var(--placeholder); }
td.pricing { color: #cbd5e1; font-variant-numeric: tabular-nums; }
body.light td.pricing { color: #334155; }

/* ---------- 行内操作 ---------- */
.row-actions { white-space: nowrap; text-align: center; }
.act { cursor: pointer; font-size: 13px; user-select: none; }
.act-update { color: var(--accent); }
.act-update:hover { color: var(--accent-hover); text-decoration: underline; }
.act-remove { color: var(--placeholder); }
.act-remove:hover { color: var(--red); }
.act-sep { color: var(--line); margin: 0 7px; }

/* ---------- 设置弹窗 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(2, 8, 18, .72);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-card h3 { font-size: 16px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal-card .text-input { margin-top: 2px; }
.cfg-row { display: flex; gap: 12px; }
.cfg-row label { flex: 1; }
.modal-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  bottom: 26px; left: 50%;
  transform: translateX(-50%);
  background: var(--hover);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 9px;
  font-size: 13px;
  z-index: 60;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.error { border-color: var(--red); }

body.light .modal { background: rgba(15, 23, 42, .38); }
body.light .toast { box-shadow: 0 8px 24px rgba(15, 23, 42, .14); }

/* ---------- 库存监控 ---------- */
.badge {
  display: inline-block;
  min-width: 17px;
  padding: 1px 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 15px;
  vertical-align: 1px;
}
.badge.hidden { display: none; }

th.star-col { width: 34px; }
td.star {
  text-align: center;
  cursor: pointer;
  font-size: 15px;
  color: var(--placeholder);
  user-select: none;
}
td.star:hover { color: var(--yellow); }
td.star.on { color: var(--yellow); }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 16px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------- 监控页 ---------- */
.watch-pane { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.watch-pane .table-wrap { flex: 1; min-height: 0; }
#watchBody td.stock { text-align: center; }
th.col-price, #watchBody td.col-price { text-align: right; padding-right: 28px; }
.delta-pos { color: var(--green); }
.delta-neg { color: var(--red); }

/* 监控启停开关：绿=启动，红=暂停 */
.switch {
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--red);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background .2s;
  padding: 0;
  vertical-align: middle;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
.switch.on { background: var(--green); }
.switch.on::after { left: 20px; }
/* 分区置灰：区域2（轮询库存）未启用轮询才灰；区域3（订阅库存）未启用订阅才灰；区域1/4 从不灰 */
tr.poll-off td:nth-child(n+5):nth-child(-n+10) { opacity: .55; }
tr.sub-off td:nth-child(n+11):nth-child(-n+15) { opacity: .55; }
tr.not-found td.part { color: var(--red); }
.nf-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(248, 113, 113, .15);
  color: var(--red);
  vertical-align: 1px;
}
td.stock.nf { color: var(--red); }

/* 分页 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 4px 0 0;
  flex-shrink: 0;
}
.pagination .small-btn { padding: 5px 12px; font-size: 12.5px; }
.pagination .small-btn:disabled { opacity: .4; cursor: default; }
.pg-size { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.pg-select {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 13px;
  outline: none;
}

/* 监控页输入框 */
#watchInput { margin-bottom: 2px; }

.act-raw { color: #60a5fa; }
.act-raw:hover { color: #93c5fd; text-decoration: underline; }
body.light .act-raw { color: #2563eb; }
body.light .act-raw:hover { color: #1d4ed8; }

/* 可点击行（异常日志行仍可点击查看详情） */
#errorsBody tr.row-click { cursor: pointer; }

/* 异常状态标 */
.err-status { font-weight: 700; }
.err-status.bad { color: var(--red); }
.err-status.ok { color: var(--yellow); }

/* 设置弹窗：Token 行 */
.token-row { display: flex; gap: 8px; margin-top: 2px; }
.token-row .text-input { flex: 1; font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.token-row .btn { flex-shrink: 0; }

/* ---------- 设置弹窗：订阅推送区 ---------- */
.cfg-divider { border-top: 1px solid var(--line); margin: 4px 0 2px; }
.cfg-section-title { font-weight: 700; font-size: 14px; margin: 4px 0 6px; }
.cfg-check {
  flex-direction: row !important;
  align-items: center;
  gap: 7px !important;
  cursor: pointer;
  color: var(--text) !important;
}
.cfg-events { margin-top: 8px; }

/* 推送记录 */
.ntf-ok { color: var(--green); font-weight: 700; }
.ntf-fail { color: var(--red); font-weight: 700; }

/* 添加料号弹窗 */
.add-textarea {
  resize: vertical;
  min-height: 130px;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.7;
  white-space: pre;
}
/* 锁定字段（只读展示，如开启订阅时的账号/料号） */
.locked-field {
  padding: 9px 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}
.locked-field.mono { font-family: Consolas, "Courier New", monospace; letter-spacing: .3px; }

/* 调用统计列表里的接口 URL */
.url-cell {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 360px;
  vertical-align: middle;
}

/* 基础设置页（复用 modal-card 卡片样式，页面内加宽） */
.settings-card { width: 560px; max-width: 96vw; align-self: flex-start; }
.cfg-section-title { font-size: 13px; font-weight: 700; color: var(--text); }
.cfg-divider { height: 1px; background: var(--line); margin: 2px 0; }
.cfg-check { flex-direction: row !important; align-items: center; gap: 8px !important; }
.cfg-events label { flex: none; }

/* 表头小字提示（如「料号 点击查看详情」） */
.th-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--placeholder);
  margin-left: 4px;
}

/* 搜索框及清空叉叉 */
.search-wrap { position: relative; display: inline-flex; align-items: center; }
.search-wrap .text-input { padding-right: 26px; }
.search-clear {
  position: absolute;
  right: 7px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  user-select: none;
}
.search-clear:hover { color: var(--text); }

/* 料号可点击（打开详情侧页） */
td.part.clickable { cursor: pointer; }
td.part.clickable:hover { color: var(--accent-hover); text-decoration: underline; }
/* 区域1 可点单元格：手型光标 + 悬停淡背景 */
#watchView td.clickable { cursor: pointer; }
#watchView td.clickable:hover { background: var(--hover); }

/* 监控表业务分组竖线：基础信息 | 轮询库存 | 订阅库存 | 操作 */
#watchView th:nth-child(5), #watchView td:nth-child(5),
#watchView th:nth-child(11), #watchView td:nth-child(11),
#watchView th:nth-child(16), #watchView td:nth-child(16) {
  border-left: 2px solid rgba(139, 152, 169, .38);
}
/* 监控表表头全部居中 */
#watchView thead th { text-align: center; }
/* 监控表数据全部居中，料号列保持左对齐 */
#watchView tbody td { text-align: center; }
#watchView tbody td.part { text-align: left; }

/* 调用统计 */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 14px;
  text-align: center;
}
.card-num { font-size: 26px; font-weight: 700; }
.card-label { color: var(--muted); font-size: 12px; margin-top: 4px; }
.chart-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px 16px;
}
.chart-title { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.bars {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 130px;
  padding-top: 6px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 100%;
}
.bar {
  width: 34px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}
.bar-num { font-size: 11px; color: var(--muted); }
.bar-label { font-size: 11px; color: var(--placeholder); }

/* 24h 库存曲线（详情侧页） */
.stock-chart {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.stock-chart svg { display: block; width: 100%; height: auto; }
.stock-chart .chart-empty {
  color: var(--placeholder);
  font-size: 12px;
  text-align: center;
  padding: 30px 0;
}
.sc-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.sc-text { fill: var(--muted); font-size: 10.5px; }
.sc-area { fill: var(--accent); opacity: .08; }
.sc-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.sc-dot { fill: var(--accent); }
.sc-dot:hover { fill: var(--accent-hover); r: 4; }

/* 产品详情侧页 */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 18, .55);
  z-index: 65;
}
body.light .drawer-backdrop { background: rgba(15, 23, 42, .3); }
.drawer {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 880px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 70;
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.drawer-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.drawer-json { max-height: none; }
.kv-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.kv-table td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(28, 42, 64, .45);
  font-size: 12.5px;
  word-break: break-all;
}
.kv-table .kv-key {
  color: var(--muted);
  width: 180px;
  font-family: Consolas, "Courier New", monospace;
}
.kv-table .kv-val { color: var(--text); }
.drawer-notice {
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .4);
  color: var(--yellow);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.7;
}

/* ---------- JSON 弹窗 ---------- */
.json-card { width: 880px; max-width: 92vw; }
.json-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.json-title {
  font-weight: 700;
  font-size: 15px;
  font-family: Consolas, "Courier New", monospace;
}
.json-btns { display: flex; gap: 8px; flex-shrink: 0; }
.modal-section-title {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 6px;
}
.json-view {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  max-height: 62vh;
  margin: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 2;
}
.j-key { color: #7dd3fc; }
.j-str { color: #86efac; }
.j-num { color: #fbbf24; }
.j-bool { color: #c084fc; }
.j-null { color: #94a3b8; }
body.light .j-key { color: #0369a1; }
body.light .j-str { color: #15803d; }
body.light .j-num { color: #b45309; }
body.light .j-bool { color: #7e22ce; }
