/* 琥珀运维 · 与琥珀快讯同一套外观（橙色品牌、左导航），浅色 / 深色两套主题 */
:root {
  --brand: #ff6b2b;
  --brand-soft: rgba(255, 107, 43, .10);
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e8eaef;
  --line-2: #f0f1f4;
  --grid: #eceef2;
  --text: #141821;
  --text-2: #3b4250;
  --muted: #6b7486;
  --chip: #f1f2f5;
  --surface: #ffffff;
  /* 状态色（固定，配图标 + 文字，不单靠颜色） */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --info: #2a78d6;
  --good-text: #087a08;
  --warning-text: #8a5d00;
  --critical-text: #b42f2f;
  --info-text: #1f5fae;
  /* 分类色（数据可视化参考色板，固定顺序；dataviz 校验器已过 light） */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s-other: #9aa1ad;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --body: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --nav-w: 216px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #070b12;
  --panel: #0c121b;
  --panel-2: #101722;
  --line: #1b2433;
  --line-2: #141c28;
  --grid: #1c2534;
  --text: #e8ebf1;
  --text-2: #c3c9d4;
  --muted: #8892a5;
  --chip: #151d29;
  --surface: #0c121b;
  --good-text: #4fd14f;
  --warning-text: #fab219;
  --critical-text: #f07070;
  --info-text: #6aa8f0;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s-other: #5d6676;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 var(--body); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
a.link { color: var(--info-text); }
a.link:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 外框 ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--panel);
  border-right: 1px solid var(--line); padding: 20px 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; }
.brand strong { display: block; font-size: 19px; letter-spacing: 1px; line-height: 1.15; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.nav-item { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-radius: 9px; color: var(--text-2); font-weight: 500; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-foot { margin-top: auto; padding: 0 10px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--muted); }
.nav-foot button { background: var(--chip); border: 0; border-radius: 8px; padding: 7px 10px; text-align: left; color: var(--text-2); }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; font-size: 11.5px; font-weight: 700; line-height: 20px; text-align: center;
  color: #fff; background: var(--critical); }
.badge.warning { background: var(--warning); color: #2b1d00; }

.main { min-width: 0; padding: 22px 28px 60px; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: .5px; }
.topbar .spacer { flex: 1; }
.topbar .stamp { color: var(--muted); font-size: 12.5px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; color: var(--text-2); }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.loading { opacity: .55; transition: opacity .2s; }

/* ---------- 卡片 / 区块 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card + .card, .section + .section { margin-top: 16px; }
.card h2, .section > h2 { margin: 0 0 12px; font-size: 15.5px; font-weight: 650; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card h2 small, .section > h2 small { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid.two > .card + .card { margin-top: 0; }
@media (max-width: 1180px) { .grid.two { grid-template-columns: minmax(0, 1fr); } }
.note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---------- 指标卡 ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; min-width: 0; }
.tile .label { font-size: 12.5px; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile .sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.tile.hero .value { font-size: 30px; }
.delta-up { color: var(--critical-text); }   /* 费用涨 = 坏 */
.delta-down { color: var(--good-text); }

/* ---------- 状态标记（图标 + 文字） ---------- */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.st.good { color: var(--good-text); }
.st.good::before { background: var(--good); }
.st.warning { color: var(--warning-text); }
.st.warning::before { background: var(--warning); border-radius: 2px; transform: rotate(45deg); width: 8px; height: 8px; }
.st.critical { color: var(--critical-text); }
.st.critical::before { background: var(--critical); border-radius: 2px; }
.st.info { color: var(--info-text); }
.st.info::before { background: transparent; border: 2px solid var(--info); width: 8px; height: 8px; }
.st.idle { color: var(--muted); font-weight: 500; }
.st.idle::before { background: var(--s-other); }

/* ---------- 告警 ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; padding: 11px 14px;
  border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 10px; background: var(--panel-2); }
.alert.critical { border-left-color: var(--critical); }
.alert.warning { border-left-color: var(--warning); }
.alert .t { font-weight: 600; overflow-wrap: anywhere; }
.alert .d { grid-column: 2 / 4; color: var(--text-2); font-size: 12.5px; overflow-wrap: anywhere; }
.alert .m { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.alert.stale { opacity: .7; }
.allgood { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 10px; background: rgba(12, 163, 12, .08); color: var(--good-text); font-weight: 600; }

/* ---------- 表格 ---------- */
.tablewrap { overflow-x: auto; margin: 0 -4px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t th.num { text-align: right; }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.bad td { background: rgba(208, 59, 59, .045); }
table.t tr.warn td { background: rgba(250, 178, 25, .06); }
table.t td .name { font-weight: 600; }
table.t td .sub { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 4px 12px; font-size: 12.5px; color: var(--text-2); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.chip .n { margin-left: 4px; color: var(--muted); font-weight: 500; }
.search { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 4px 12px; font-size: 12.5px; min-width: 200px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; background: var(--chip); color: var(--text-2); font-size: 11.5px; line-height: 19px; white-space: nowrap; }
.proj { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
details.more > summary { cursor: pointer; color: var(--info-text); font-size: 12.5px; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
.sql { font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-all; background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; margin: 6px 0; color: var(--text-2); }
.gaps { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }

/* ---------- 图表 ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis text, .chart text.axis { fill: var(--muted); font-size: 11px; font-family: var(--body); }
.chart .hit { fill: transparent; cursor: default; }
.chart .col:hover .seg, .chart .col:focus .seg { filter: brightness(1.12); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-2); margin: 2px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.spark { display: block; }
.spark .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--s1); opacity: .1; }
.spark .err { fill: var(--critical); }
.strip { display: inline-flex; gap: 2px; vertical-align: middle; }
.strip i { width: 6px; height: 16px; border-radius: 2px; background: var(--good); display: block; }
.strip i.part { background: var(--warning); }
.strip i.down { background: var(--critical); }
.strip i.none { background: var(--line); }
.bar { height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--s1); }
.bar.warn > i { background: var(--warning); }
.bar.bad > i { background: var(--critical); }

.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 6px 24px rgba(16, 24, 40, .14); padding: 8px 11px; font-size: 12.5px; min-width: 140px; max-width: 320px; }
.tip .h { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.tip .r b { font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.tip .r .lk { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tip .r.total { border-top: 1px solid var(--line); margin-top: 3px; padding-top: 3px; }

/* ---------- 登录 ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 10px; text-align: center; align-items: center; }
.login h1 { margin: 4px 0 0; font-size: 22px; }
.login p { margin: 0 0 8px; font-size: 13px; }
.login input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: var(--panel-2); }
.login button { width: 100%; border: 0; border-radius: 9px; padding: 9px 12px; background: var(--brand); color: #fff; font-weight: 600; }
.login-err { color: var(--critical-text) !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; gap: 4px; }
  .brand { padding: 0 8px 0 4px; }
  .brand small { display: none; }
  .nav-foot { display: none; }
  .main { padding: 14px 12px 40px; }
  .alert { grid-template-columns: 64px minmax(0, 1fr); }
  .alert .m { grid-column: 2; text-align: left; }
}

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: #141821; color: #fff; border-radius: 10px; padding: 9px 16px; font-size: 13px; transition: all .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
