:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --line: #e4e7ec;
  --text: #182230;
  --muted: #667085;
  --green: #087e5b;
  --green-soft: #eaf7f2;
  --red: #c43b4d;
  --red-soft: #fff0f2;
  --blue: #315cc8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, ui-sans-serif, system-ui, "Microsoft YaHei", sans-serif; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.topbar { min-height: 64px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 240px 1fr auto; align-items: center; gap: 20px; }
.identity { display: flex; align-items: center; gap: 10px; }
.identity div { display: flex; flex-direction: column; }
.identity strong { font-size: 15px; }
.identity span { color: var(--muted); font-size: 11px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; background: #17212f; color: white; font-weight: 800; font-size: 15px; border-radius: 6px; }
.brand-mark.small { width: 36px; height: 36px; font-size: 12px; color: white; }
.runtime-strip { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 9px 14px; min-width: 0; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #98a2b3; box-shadow: 0 0 0 3px #eaecf0; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.quiet-button { border: 1px solid var(--line); background: var(--surface); color: #344054; border-radius: 5px; padding: 7px 12px; }
.quiet-button:hover { background: #f2f4f7; }
.quiet-button:disabled { cursor: default; opacity: .45; }

.view-tabs { min-height: 48px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: stretch; gap: 4px; position: sticky; top: 0; z-index: 5; }
.tab { min-width: 92px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 0 14px; font-weight: 600; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.range-control { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.range-control button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 4px; }
.range-control button.active { background: #eef2ff; color: var(--blue); font-weight: 700; }

main { width: min(1440px, 100%); margin: 0 auto; padding: 26px 28px 48px; }
.section-heading, .subheading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.section-heading { margin-bottom: 20px; }
.section-heading h1 { margin: 0; font-size: 26px; line-height: 1.2; }
.eyebrow { margin: 0 0 4px; color: var(--blue); font-size: 11px; font-weight: 800; }
.metrics { background: var(--surface); border-block: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, 1fr); margin-inline: -28px; padding-inline: 28px; }
.metrics > div { min-height: 112px; padding: 22px 26px; border-right: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; align-content: center; column-gap: 6px; }
.metrics > div:first-child { padding-left: 0; }
.metrics > div:last-child { border-right: 0; }
.metrics span { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.metrics strong { font-size: clamp(22px, 2.4vw, 32px); line-height: 1.1; font-variant-numeric: tabular-nums; }
.metrics small { align-self: end; color: var(--muted); padding-bottom: 2px; }

.chart-section, .position-section, .events-section { padding-top: 28px; }
.subheading { align-items: center; margin-bottom: 14px; }
.subheading h2 { margin: 0; font-size: 16px; }
.chart-wrap { position: relative; width: 100%; height: 360px; background: var(--surface); border-block: 1px solid var(--line); margin-inline: -28px; width: calc(100% + 56px); padding-inline: 10px; }
.chart-wrap canvas { display: block; width: 100%; height: 100%; }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.phase-label { font-family: ui-monospace, monospace; color: var(--blue); }
.position-grid { display: grid; grid-template-columns: repeat(6, 1fr); margin: 0; background: var(--surface); border-block: 1px solid var(--line); }
.position-grid div { padding: 16px 18px; border-right: 1px solid var(--line); min-width: 0; }
.position-grid div:last-child { border-right: 0; }
.position-grid dt { color: var(--muted); font-size: 12px; }
.position-grid dd { margin: 4px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; background: var(--surface); border-block: 1px solid var(--line); margin-inline: -28px; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #eef0f3; vertical-align: top; }
th { color: var(--muted); background: #fafbfc; font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.event-details { color: #475467; min-width: 300px; overflow-wrap: anywhere; }
.qq-status { display: inline-block; white-space: nowrap; padding: 2px 7px; border-radius: 4px; font-size: 12px; background: #f2f4f7; color: var(--muted); }
.qq-status.sent { background: var(--green-soft); color: var(--green); }
.qq-status.failed { background: var(--red-soft); color: var(--red); }
.empty-row { text-align: center; color: var(--muted); padding: 40px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.page-error { position: fixed; right: 24px; bottom: 24px; max-width: 420px; background: #7a1f2b; color: white; padding: 12px 16px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }

.login-page { min-height: 100vh; display: grid; place-items: center; background: #eef1f5; padding: 20px; }
.login-shell { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); padding: 34px; box-shadow: 0 18px 50px rgba(16,24,40,.08); }
.login-shell h1 { margin: 22px 0 2px; font-size: 23px; }
.login-shell > p { margin: 0 0 25px; }
.login-form { display: grid; gap: 8px; }
.login-form label { color: #344054; font-weight: 600; margin-top: 7px; }
.login-form input { width: 100%; border: 1px solid #cfd4dc; border-radius: 5px; padding: 10px 11px; outline: none; }
.login-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #e8edff; }
.login-form button { margin-top: 12px; border: 0; border-radius: 5px; padding: 11px; background: #17212f; color: white; font-weight: 700; }
.form-error { color: var(--red); margin: 5px 0 0; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; padding: 10px 16px; }
  .runtime-strip { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; border-top: 1px solid var(--line); padding-top: 9px; }
  .view-tabs { padding: 0 12px; overflow-x: auto; }
  .tab { min-width: 82px; }
  .range-control { position: sticky; right: 0; background: var(--surface); padding-left: 8px; }
  main { padding: 22px 18px 40px; }
  .metrics { grid-template-columns: repeat(2, 1fr); margin-inline: -18px; padding-inline: 18px; }
  .metrics > div:nth-child(2) { border-right: 0; }
  .metrics > div:first-child { padding-left: 12px; }
  .metrics > div { min-height: 94px; padding: 16px 12px; border-bottom: 1px solid var(--line); }
  .metrics > div:nth-child(n+3) { border-bottom: 0; }
  .chart-wrap, .table-wrap { margin-inline: -18px; width: calc(100% + 36px); }
  .chart-wrap { height: 300px; }
  .position-grid { grid-template-columns: repeat(3, 1fr); }
  .position-grid div:nth-child(3n) { border-right: 0; }
  .position-grid div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 560px) {
  .identity div span, #runtime-next { display: none; }
  .runtime-strip { gap: 7px 11px; }
  .runtime-strip .muted { font-size: 12px; }
  .view-tabs { min-height: 92px; flex-wrap: wrap; align-content: center; overflow: visible; }
  .tab { height: 42px; flex: 1; }
  .range-control { order: 2; width: 100%; height: 42px; justify-content: space-between; padding: 0; }
  .range-control button { flex: 1; }
  .section-heading { align-items: flex-start; }
  .section-heading h1 { font-size: 23px; }
  .metrics strong { font-size: 21px; }
  .chart-wrap { height: 270px; }
  .position-grid { grid-template-columns: repeat(2, 1fr); }
  .position-grid div:nth-child(3n) { border-right: 1px solid var(--line); }
  .position-grid div:nth-child(2n) { border-right: 0; }
  .position-grid div:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
  .position-grid div:nth-child(n+5) { border-bottom: 0; }
  .login-shell { padding: 26px; }
}
