/* Frosted-glass theme. Colors and glass strength are driven by CSS variables. */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", sans-serif;
  --blur: 20px;
  --card-min: 300px;
  --radius: 16px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-primary: #cfd6e4;
  --text: #1c2431;
  --muted: rgba(28, 36, 49, 0.62);
  --faint: rgba(28, 36, 49, 0.42);
  --glass: rgba(255, 255, 255, 0.66);
  --edge: rgba(255, 255, 255, 0.72);
  --line: rgba(28, 36, 49, 0.1);
  --shadow: 0 8px 30px rgba(40, 55, 90, 0.14);
  --track: rgba(28, 36, 49, 0.1);
  --tipbg: rgba(255, 255, 255, 0.95);
  --veil: transparent;
  --acc: #3f6fb5;
  --good: #2fa866;
  --warn: #e0a02a;
  --bad: #d64b4b;
  --c0: #3f6fb5; --c1: #2c9a77; --c2: #b57a12; --c3: #8a55b8;
  --c4: #c94b4b; --c5: #2a8aa3; --c6: #7c8a2a; --c7: #b5693c;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-primary: #12151b;
  --text: #e9edf3;
  --muted: rgba(233, 237, 243, 0.62);
  --faint: rgba(233, 237, 243, 0.4);
  --glass: rgba(20, 25, 36, 0.5);
  --edge: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.34);
  --track: rgba(255, 255, 255, 0.12);
  --tipbg: rgba(24, 28, 36, 0.95);
  --veil: rgba(6, 8, 14, 0.4);
  --acc: #8db4ea;
  --good: #52c98a;
  --warn: #e5b567;
  --bad: #ee7b7b;
  --c0: #8db4ea; --c1: #7fcfb0; --c2: #e5b567; --c3: #c79bea;
  --c4: #ee8f8f; --c5: #7fc8d9; --c6: #b4c27a; --c7: #d99a74;
}

* { box-sizing: border-box; }
html { background-color: var(--bg-primary); }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg-primary);
  /* Built-in background; a background image set in the admin panel is injected with !important and wins. */
  background-image: url(bg.webp);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
#veil { position: fixed; inset: 0; background: var(--veil); pointer-events: none; z-index: 0; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 4px; }

.wrap { position: relative; z-index: 1; max-width: 1240px; margin: 0 auto; padding: 28px 24px 36px; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

.card {
  min-width: 0;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  backdrop-filter: blur(var(--blur)) saturate(140%);
}

/* header / footer */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.brand { font-size: 18px; font-weight: 600; letter-spacing: 0.01em; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: 13px; }
.nav a:hover, .link:hover { color: var(--text); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.foot { margin-top: 36px; text-align: center; font-size: 12px; }
.foot a, .live-line { color: rgba(255, 255, 255, 0.82); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }
.foot a:hover { color: #fff; }

/* totals */
.summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile.card { padding: 14px 18px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.k { color: var(--muted); font-size: 12px; }
.val { white-space: nowrap; }
.val b { font-weight: 600; }
.val small { font-size: 0.62em; font-weight: 500; color: var(--faint); }
.val.big { font-size: 26px; line-height: 1.15; }
.val.big small { font-size: 13px; }
.num { font-size: 16px; font-weight: 600; white-space: nowrap; }

/* group tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 14px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 4px 10px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); font-weight: 600; border-bottom-color: var(--text); }

/* server grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min)), 1fr)); gap: 16px; }
.srv { display: flex; flex-direction: column; gap: 12px; padding: 16px 18px 18px; min-width: 0; transition: opacity 0.25s; }
.srv:hover { text-decoration: none; }
.srv.is-off { opacity: 0.62; }
.srv-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.srv-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag { width: 22px; height: 15px; object-fit: cover; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px var(--line); }
.osi { width: 13px; height: 13px; object-fit: contain; flex: none; }
.srv-sub { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; min-width: 0; margin-top: -6px; }
.srv-sub > span:not(.sep) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sep { color: var(--faint); }

.st { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 12px; color: var(--muted); }
.st .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.st.on .dot { background: var(--good); }
.st.off .dot { background: var(--bad); }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.mt { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.m-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; }
.m-l { color: var(--text); }
.m-v { font-weight: 600; }
.m-d { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 3px; border-radius: 2px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.4s ease; }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }

.nets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: 12px; padding: 10px 0 0; border-top: 1px solid var(--line); }
.nets > div { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.nets .v { font-weight: 500; white-space: nowrap; }

.lat { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.lat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.lc { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.lh { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; font-size: 12px; }
.ln { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lh .val { font-weight: 600; font-size: 13px; }
.lv.warn, .ll.warn, .val.warn { color: var(--warn); }
.lv.bad, .ll.bad, .val.bad { color: var(--bad); }
.strip { display: block; width: 100%; height: 8px; }
.strip rect { fill: var(--track); }
.strip rect.g { fill: var(--good); }
.strip rect.y { fill: var(--warn); }
.strip rect.r { fill: var(--bad); }

.live-line { margin-top: 18px; text-align: right; font-size: 12px; }
.notice, .error, .empty { margin: 0 0 14px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--glass); color: var(--muted); font-size: 13px; }
.notice .link, .error .link { margin-left: 10px; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.notice a { text-decoration: underline; text-underline-offset: 3px; }
.error { color: var(--bad); grid-column: 1 / -1; }
.empty { grid-column: 1 / -1; text-align: center; padding: 48px 16px; }
.empty a { text-decoration: underline; text-underline-offset: 3px; }
[hidden] { display: none !important; }

.gate { max-width: 420px; margin: 18vh auto 0; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; color: var(--muted); }

/* detail */
.detail { display: flex; flex-direction: column; gap: 16px; }
.crumb .back { color: var(--muted); font-size: 13px; }
.crumb .back:hover { color: var(--text); }
.host { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.host .srv-name { font-size: 20px; }
.host h1.srv-name { margin: 0; }
.sec { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; margin-bottom: 12px; }
.sec.sub-sec { margin-top: 18px; }
.info, .metrics { padding: 18px 20px; }
.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 32px; }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.row .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px 24px; }
.tiles .tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tiles .num { font-size: 18px; white-space: normal; overflow-wrap: anywhere; }
.sub { font-size: 12px; color: var(--faint); }
.tiles .num.sm { font-size: 14px; }
.lat-lines { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 32px; }
.lat-line { display: grid; grid-template-columns: minmax(0, 1fr) 70px 90px; gap: 8px; font-size: 13px; }

.range-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.range-row .sec { margin: 0; }
.ranges { display: flex; gap: 4px; flex-wrap: wrap; }
.rng { background: none; border: 0; border-bottom: 1px solid transparent; padding: 3px 8px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.rng:hover { color: var(--text); }
.rng.on { color: var(--text); border-bottom-color: var(--text); }

.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.chart-card { padding: 14px 16px 10px; position: relative; min-width: 0; }
.chart-card.wide { grid-column: span 2; }
.chart { position: relative; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg b { font-weight: 600; color: var(--text); min-width: 40px; text-align: right; }
.stage { width: 100%; }
.stage svg { display: block; width: 100%; height: 168px; }

.s0 { --c: var(--c0); } .s1 { --c: var(--c1); } .s2 { --c: var(--c2); } .s3 { --c: var(--c3); }
.s4 { --c: var(--c4); } .s5 { --c: var(--c5); } .s6 { --c: var(--c6); } .s7 { --c: var(--c7); }
.lg i, .tip i { width: 10px; height: 2px; background: var(--c); display: inline-block; flex: none; }
.pl.s0, .pl.s1, .pl.s2, .pl.s3, .pl.s4, .pl.s5, .pl.s6, .pl.s7 { fill: none; stroke: var(--c); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.pt.s0, .pt.s1, .pt.s2, .pt.s3, .pt.s4, .pt.s5, .pt.s6, .pt.s7 { fill: var(--c); }
.area.s0, .area.s1, .area.s2, .area.s3, .area.s4, .area.s5, .area.s6, .area.s7 { fill: var(--c); fill-opacity: 0.12; stroke: none; }
svg line.gl { stroke: var(--line); stroke-width: 1; }
.ax { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.cursor { stroke: var(--muted); stroke-width: 1; }
.miss { stroke: var(--bad); stroke-width: 1.5; }
.tip { position: absolute; z-index: 5; min-width: 150px; padding: 8px 10px; background: var(--tipbg); border: 1px solid var(--line); border-radius: 8px; font-size: 12px; pointer-events: none; box-shadow: var(--shadow); }
.tip-time { color: var(--muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row span { flex: 1; color: var(--muted); }
.tip-row b { font-weight: 600; }

@media (max-width: 1100px) {
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .chart-card.wide { grid-column: auto; }
}
@media (max-width: 767px) {
  /* iOS ignores fixed backgrounds, so paint the image on a fixed pseudo element instead. */
  body { background-image: none; }
  body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background-image: url(bg.webp); background-size: cover; background-position: center; }
}
@media (max-width: 640px) {
  .wrap { padding: 18px 14px 28px; }
  .grid, .charts { gap: 12px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .val.big { font-size: 22px; }
  .rows, .lat-lines { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .lat-line { grid-template-columns: minmax(0, 1fr) 64px 82px; }
}
@media (prefers-reduced-motion: reduce) {
  .bar i, .srv { transition: none; }
}
