:root {
  --bg: #0f1319;
  --bg2: #161b24;
  --panel: #1a2029;
  --line: #262f3c;
  --tx: #dbe3ee;
  --tx2: #8f9db2;
  --acc: #4aa8ff;
  --ath: #ff4d6d;
  --spike: #ff9f43;
  --elev: #ffd93d;
  --norm: #7f8c9b;
  --ok: #46d39a;
  --warn: #ffb020;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: 14px/1.5 "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--acc); text-decoration: none; }
h3 { margin: 0 0 10px; font-size: 15px; }

/* ---------- 頂列 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #151b25, #10151d);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand .logo { font-size: 22px; color: var(--acc); }
.brand .t1 { font-weight: 700; letter-spacing: .5px; }
.brand .t2 { font-size: 11px; color: var(--tx2); }

.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  padding: 7px 13px;
  border-radius: 7px;
  color: var(--tx2);
  font-weight: 500;
}
.tabs a:hover { background: #1e2530; color: var(--tx); }
.tabs a.on { background: #223047; color: #cfe4ff; }

.topright { display: flex; align-items: center; gap: 10px; }
.worldsel { color: var(--tx2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
select, input, textarea {
  background: #10151d;
  color: var(--tx);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--acc); }

.btn {
  background: #24304a;
  color: #d6e6ff;
  border: 1px solid #31435f;
  border-radius: 7px;
  padding: 7px 13px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: #2c3c5c; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--tx2); }
.btn.ghost:hover { color: var(--tx); border-color: #3a4657; }
.btn.danger { color: #ff9aa8; border-color: #4a2a33; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.conn { font-size: 12px; }
.conn.on { color: var(--ok); }
.conn.off { color: #55606f; }

.pill {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #2a3547;
  font-size: 11px;
  text-align: center;
}
.pill.warn { background: #4a3620; color: #ffcf8b; }

/* ---------- 版面 ---------- */
main { padding: 18px; max-width: 1400px; margin: 0 auto; }
.page { display: flex; flex-direction: column; gap: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.panelhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--tx2); font-size: 12px; }
.sect { margin-top: 8px; color: var(--tx2); font-size: 13px; }

/* ---------- 搜尋 ---------- */
.searchbox { display: flex; gap: 8px; }
.searchbox input { flex: 1; padding: 11px 14px; font-size: 15px; }

.search-layout { display: grid; grid-template-columns: 1fr 250px; gap: 16px; align-items: start; }
.search-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.search-side { position: sticky; top: 74px; }
@media (max-width: 980px) { .search-layout { grid-template-columns: 1fr; } .search-side { position: static; } }

.hist-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--tx);
}
.hist-item:hover { background: #1f2733; }
.hist-item .hq { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .hn { color: var(--tx2); font-size: 11px; flex: none; }
.hist-item .hx { color: #55606f; border: 0; background: none; cursor: pointer; padding: 0 2px; }
.hist-item .hx:hover { color: #ff8195; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.card {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 34px 10px 10px;
  cursor: pointer;
}
.card:hover { border-color: #3d5a80; background: #1e2632; }
.card img { width: 36px; height: 36px; border-radius: 5px; background: #0d1119; flex: none; }
.card .n1 { font-weight: 600; }
.card .n2 { font-size: 11px; color: var(--tx2); }
.card .txt { min-width: 0; }
.card .n1, .card .n2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fav {
  position: absolute; right: 6px; bottom: 5px;
  background: none; border: 0; cursor: pointer; padding: 3px 5px;
  font-size: 16px; line-height: 1; color: #46536a; border-radius: 6px;
}
.fav:hover { color: #ff8195; background: #232b36; }
.fav.on { color: #ff4d6d; }
.fav.busy { opacity: .4; pointer-events: none; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 9px; text-align: right; border-bottom: 1px solid #202834; white-space: nowrap; }
th { color: var(--tx2); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--panel); }
td.l, th.l { text-align: left; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #1f2733; }
.tblwrap { max-height: 420px; overflow: auto; }
.mono { font-variant-numeric: tabular-nums; }
.best { color: var(--ok); font-weight: 700; }
.muted { color: var(--tx2); }

/* ---------- 分級標籤 ---------- */
.tier {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}
.tier.ath { background: #40151f; color: #ff8195; border-color: #7a2536; }
.tier.spike { background: #402713; color: #ffb877; border-color: #7a4a20; }
.tier.elevated { background: #3b3512; color: #ffe680; border-color: #6f6320; }
.tier.dip { background: #10324a; color: #6fc7ff; border-color: #1d5478; }
/* 便宜了，但還沒跌到過去版本的低檔 —— 值得盯，還不值得叫你 */
.tier.watchbuy { background: #1a2c38; color: #8fb4c9; border-color: #2b4759; }
.tier.normal, .tier.weak, .tier.small, .tier.insufficient, .tier.nolisting {
  background: #232b36; color: var(--norm); border-color: #303a49;
}
.tier.target { background: #14352c; color: #6ee7b7; border-color: #245c4a; }

/* ---------- 物品頁 ---------- */
.itemhead { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.itemhead img { width: 52px; height: 52px; border-radius: 8px; background: #0d1119; }
.itemhead .name { font-size: 20px; font-weight: 700; }
.itemhead .sub { color: var(--tx2); font-size: 12px; }
.spacer { flex: 1; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { background: #141a23; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.kpi .k { font-size: 11px; color: var(--tx2); }
.kpi .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .v.sm { font-size: 15px; }

.reasons { margin: 6px 0 0; padding-left: 18px; color: #cbd6e5; font-size: 13px; }
.gates { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.gate { font-size: 11px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--tx2); }
.gate.ok { color: var(--ok); border-color: #24503f; }
.gate.no { color: #ff8195; border-color: #4a2731; }

/* ---------- 圖表 ---------- */
.chart-box { position: relative; }
.chart-svg { display: block; width: 100%; height: auto; }
.chart-empty { color: var(--tx2); padding: 60px 0; text-align: center; }
.ch-hit { cursor: crosshair; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: #0e131b;
  border: 1px solid #33425a;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12px;
  min-width: 180px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .55);
  z-index: 5;
}
.chart-tip .tip-t { color: var(--tx2); margin-bottom: 5px; font-size: 11px; }
.chart-tip .tip-r { display: flex; justify-content: space-between; gap: 14px; line-height: 1.7; }
.chart-tip .tip-r span { color: var(--tx2); }
.chart-tip .tip-r b { font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 16px; color: var(--tx2); font-size: 12px; margin-top: 10px; flex-wrap: wrap; }
.legend .band {
  display: inline-block; width: 14px; height: 9px; margin-right: 5px; vertical-align: middle;
  background: linear-gradient(180deg, rgba(74, 168, 255, .45), rgba(74, 168, 255, .1));
  border-radius: 2px;
}
.legend .line { display: inline-block; width: 14px; height: 0; border-top: 2px solid; margin-right: 5px; vertical-align: middle; }
.legend .line.nq { border-color: #4aa8ff; }
.legend .line.hq { border-color: #ffd93d; }
.legend .line.cur { border-top-style: dotted; border-color: #b07cff; }
.legend .line.med { border-top-style: dashed; border-color: #46d39a; }
.legend .line.ath { border-top-style: dashed; border-color: #ff4d6d; }
.legend .line.patch { border-top-style: dashed; border-color: #ff77c8; }

.chartctl { gap: 8px; margin-bottom: 6px; }
.chartctl .seg button { padding: 4px 10px; font-size: 12px; }
.chart-tip .tip-h { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.chart-tip .tip-t { color: var(--tx2); font-size: 11px; margin-top: 5px; }

.panelhead.wrap { flex-wrap: wrap; }

/* ---------- 對話框 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 9, 14, .62);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid #33425a; border-radius: 12px;
  width: min(620px, 96vw); max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-head .mt { font-weight: 700; font-size: 15px; }
.modal-head .ms { color: var(--tx2); font-size: 12px; }
.modal-head .x { background: none; border: 0; color: var(--tx2); font-size: 18px; cursor: pointer; padding: 0 4px; }
.modal-head .x:hover { color: var(--tx); }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.modal .formgrid { grid-template-columns: 150px 1fr; gap: 12px 14px; }
.modal .formgrid input, .modal .formgrid select { width: 100%; }
@media (max-width: 560px) { .modal .formgrid { grid-template-columns: 1fr; gap: 6px; } }

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button {
  background: transparent; color: var(--tx2); border: 0; padding: 5px 12px; cursor: pointer; font: inherit;
}
.seg button.on { background: #223047; color: #cfe4ff; }

/* ---------- 設定 ---------- */
.formgrid { display: grid; grid-template-columns: 220px 1fr; gap: 10px 14px; align-items: center; }
.formgrid .full { grid-column: 1 / -1; }
.formgrid label { color: var(--tx2); font-size: 13px; }
.formgrid .desc { grid-column: 2; color: var(--tx2); font-size: 11px; margin-top: -6px; }
.chk { display: flex; gap: 14px; flex-wrap: wrap; }
.chk label { display: flex; align-items: center; gap: 5px; color: var(--tx); }

/* ---------- 通知 toast ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: #1c2431;
  border: 1px solid #33506e;
  border-left: 4px solid var(--ath);
  border-radius: 9px;
  padding: 11px 14px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
  cursor: pointer;
  animation: slidein .25s ease;
}
.toast .tt { font-weight: 700; margin-bottom: 3px; }
.toast .tb { font-size: 12px; color: #c3cede; white-space: pre-wrap; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { color: var(--tx2); padding: 24px; text-align: center; }
.err { color: #ff8195; }

/* ---------- 追蹤清單大表 ---------- */
.tblwrap.wide { max-height: calc(100vh - 260px); }
table.watch th, table.watch td { vertical-align: top; }
/* 欄位很多要橫向捲，物品欄釘住才不會捲一捲不知道在看哪一列 */
table.watch th.stick, table.watch td.stick {
  position: sticky; left: 0; z-index: 3;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
  min-width: 190px;
}
table.watch thead th.stick { z-index: 4; }
table.watch tr:hover td.stick { background: #1f2733; }
table.watch th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.watch th.sortable:hover { color: var(--tx); }
/* 各版本平穩價的欄位視覺上收斂一點，不要跟主要數字搶注意力 */
table.watch th.cyc, table.watch td.cyc {
  background: #151b24; color: var(--tx2); font-size: 12px; padding-left: 6px; padding-right: 6px;
}
table.watch th.cyc { color: #6fc7ff; }
.err { color: #ff8195; }
/* ---------- 編輯權限：唯讀 / 解鎖 ---------- */
#gateBtn.on { color: #6ee7b7; border-color: #245c4a; background: #14352c; }

.gatemodal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(6, 9, 13, 0.72);
  display: flex; align-items: center; justify-content: center;
}
.gatebox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  width: min(360px, calc(100vw - 32px));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}
.gatebox h3 { margin: 0 0 6px; font-size: 16px; }
.gatebox p { margin: 0 0 14px; }
.gatebox input[type='password'] {
  width: 100%; box-sizing: border-box;
  padding: 9px 11px; font-size: 14px;
  background: #10151d; color: var(--tx);
  border: 1px solid var(--line); border-radius: 6px;
}
.gatebox input[type='password']:focus { outline: 1px solid var(--acc); }
.gateerr { color: #ff8195; font-size: 13px; min-height: 18px; margin-top: 6px; }
