:root {
  font-family: Inter, "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #172832;
  background: #f5f7f8;
  font-synthesis: none;
  font-size: 14px;
  --background: #f5f7f8;
  --card: #fff;
  --side: #edf1f3;
  --line: #dbe3e8;
  --ink: #172832;
  --muted: #526572;
  --accent: #056c69;
  --accent-quiet: #e1f2ed;
  --danger: #9b3236;
  --danger-quiet: #f9ebeb;
  --warning: #7b500e;
  --warning-quiet: #f8efda;
  --radius: 7px;
  --gutter: clamp(12px, 1.8vw, 32px);
  --inset: clamp(10px, 1.65vh, 24px);
  --gap: clamp(10px, 1.5vmin, 18px);
  --plot-min: 120px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, p, h1, h2, dl, dd { margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
button, input, select { font: inherit; }
:is(a, button, input, select, canvas):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { min-height: 35px; padding: 6px 13px; border-radius: var(--radius); border: 1px solid var(--line); cursor: pointer; background: var(--card); color: var(--ink); font-weight: 550; }
button:hover { background: var(--background); }
button:disabled { opacity: .52; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: transparent; }
button.primary:not(:disabled):hover { background: #075a58; }
button.quiet { background: transparent; color: var(--muted); }
button.link-button { min-height: auto; padding: 0; border: 0; color: var(--accent); background: transparent; text-align: start; }
button.link-button:hover { text-decoration: underline; text-underline-offset: 3px; }
button.danger { color: var(--danger); }
label { display: grid; gap: 6px; min-width: 0; color: var(--muted); font-size: 13px; font-weight: 550; }
input, select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 37px;
  padding: 7px 9px;
  border: 1px solid #c9d4dc;
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--card);
}
input[readonly] { background: var(--background); color: var(--muted); }
h1 { font-size: 27px; font-weight: 670; letter-spacing: -.018em; }
h2 { font-size: 16px; font-weight: 650; }
small { font-size: 12px; color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: end; white-space: nowrap; }
.code { font-family: "IBM Plex Mono", Consolas, monospace; font-size: .94em; overflow-wrap: anywhere; }

.app {
  display: grid;
  grid-template-columns: clamp(156px, 15vw, 224px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  block-size: 100vh;
  block-size: 100dvh;
}
.sidebar {
  min-block-size: 0;
  min-inline-size: 0;
  padding: var(--inset) 14px;
  background: var(--side);
  border-inline-end: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 700; font-size: 17px; text-decoration: none; white-space: nowrap; }
.brand-sign { position: relative; width: 20px; height: 20px; display: block; background: var(--accent); border-radius: 4px; }
.brand-sign::before { position: absolute; inset: 9px 4px auto; height: 2px; background: #fff; content: ''; }
.brand-sign::after { position: absolute; inset: 4px auto 4px 8px; width: 2px; background: #fff; content: ''; transform: skew(-18deg); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-block-start: clamp(14px, 3vh, 29px); }
.sidebar nav a { padding: 9px 12px; border-radius: var(--radius); color: var(--muted); text-decoration: none; white-space: nowrap; }
.sidebar nav a:hover { color: var(--ink); background: var(--card); }
.sidebar nav a[aria-current="page"] { color: #065b58; background: #dceee9; font-weight: 650; }
.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-block-size: 0;
  min-inline-size: 0;
}
.topbar { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px var(--gutter); background: var(--card); border-bottom: 1px solid var(--line); }
.topbar p { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: end; gap: 6px; }
.view {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  min-inline-size: 0;
  padding: var(--inset) var(--gutter);
  gap: var(--gap);
  container-type: inline-size;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.view > .page-head { flex: none; }
.page-body.stack { display: flex; flex: 1 0 auto; flex-direction: column; gap: var(--gap); }
.page-head, .panel-head, .form-actions, .pagination { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.panel { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { min-width: 0; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.panel .spacing { padding: 15px; }
.stack { display: grid; gap: 12px; min-width: 0; align-content: start; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; line-height: 1.5; }
.inline-error { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 13px 15px; border-radius: var(--radius); background: var(--danger-quiet); color: var(--danger); }
.form-error { color: var(--danger); font-size: 13px; line-height: 1.5; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: var(--gap); }
.stat { display: grid; gap: 7px; padding: 14px 15px; }
.stat dt { color: var(--muted); font-size: 13px; }
.stat dd { font-size: 25px; font-weight: 650; letter-spacing: -.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat dd.compact-number { font-size: 18px; letter-spacing: 0; }
.stat .stat-note { color: var(--muted); font-size: 12px; }
.status { display: inline-flex; gap: 5px; align-items: center; width: fit-content; padding: 3px 7px; border-radius: 4px; background: var(--side); color: var(--muted); font-size: 12px; white-space: nowrap; }
.status.online, .status.recovered, .status.valid, .status.ok { background: var(--accent-quiet); color: #075953; }
.status.offline, .status.critical, .status.revoked, .status.failed, .status.error { background: var(--danger-quiet); color: var(--danger); }
.status.warning, .status.active, .status.expired { background: var(--warning-quiet); color: var(--warning); }

.table-wrap { max-inline-size: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: start; }
table:has(th:nth-child(5)) { min-inline-size: 42rem; }
table:has(.log-message) { min-inline-size: 49rem; }
td:has(.code) { min-inline-size: 7rem; }
td:first-child:has(.link-button) { min-inline-size: 8.5rem; }
td .link-button { overflow-wrap: anywhere; }
th, td { padding: 10px 13px; text-align: start; vertical-align: top; }
th { color: var(--muted); background: #f8fafa; white-space: nowrap; font-weight: 600; }
td { border-top: 1px solid var(--line); overflow-wrap: anywhere; }
td .stacked { display: block; margin-top: 4px; color: var(--muted); }
td time { white-space: nowrap; }
tbody tr:hover { background: #f8fbfa; }
.pagination { padding: 11px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.pagination > div { display: flex; align-items: center; gap: 7px; }
.filters { display: flex; align-items: end; flex-wrap: wrap; gap: var(--gap); padding: clamp(9px, 1.6vmin, 14px); }
.filters > label { flex: 1 1 126px; }
.filters > label:has(input[type="datetime-local"]), .filters > label.wide-filter { flex-basis: 165px; }
.filters .filter-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); align-items: start; }
.site-config { display: grid; gap: 10px; padding: 14px; }
.site-config .form-actions { justify-content: end; }
.selected-row td { background: #edf7f4; }
.cert-table td:first-child { min-width: 108px; }
.cert-table td:last-child { white-space: nowrap; }
.log-message { min-width: min(260px, 70vw); max-width: 66ch; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45; }
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  flex: 1 0 auto;
  min-inline-size: 0;
  gap: var(--gap);
}
.chart, [data-chart-body] { display: flex; flex-direction: column; min-inline-size: 0; min-block-size: 0; }
[data-chart-body] { flex: 1; }
[data-chart-body] > :is(.empty, .inline-error) {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-block-size: calc(var(--plot-min) + 54px);
}
.chart-select { width: min(100%, 180px); }
.chart-view {
  flex: 1;
  min-inline-size: 0;
  min-block-size: 0;
  display: grid;
  grid-template-rows: minmax(var(--plot-min), 1fr) auto auto;
  padding: 8px 13px 10px;
  gap: 6px;
}
.plot-frame { position: relative; min-inline-size: 0; min-block-size: var(--plot-min); }
.plot { display: block; position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
.chart-caption, .chart-legend { display: flex; gap: 4px 11px; flex-wrap: wrap; min-height: 18px; color: var(--muted); font-size: 12px; }
.chart-legend .legend-entry { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.chart-legend .legend-entry > span, .chart-caption > span { min-width: 0; overflow-wrap: anywhere; }
.chart-legend .legend-swatch { flex: none; width: 12px; height: 3px; background: var(--series, var(--accent)); }

dialog {
  width: min(535px, calc(100% - 24px));
  max-block-size: calc(100vh - 24px);
  max-block-size: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--card);
}
dialog > .panel-head { position: sticky; inset-block-start: 0; z-index: 1; background: var(--card); }
dialog::backdrop { background: #20333f88; }
.dialog-body { padding: 16px; display: grid; gap: 13px; }
.dialog-body .form-actions { justify-content: end; }
.detail { display: grid; grid-template-columns: minmax(110px, .65fr) minmax(0, 1fr); gap: 9px 11px; line-height: 1.4; }
.detail dt { color: var(--muted); }
.detail dd { overflow-wrap: anywhere; }
.notice { position: fixed; inset: auto 18px 18px auto; max-width: calc(100% - 36px); padding: 10px 13px; background: #e4f2ed; border: 1px solid #b7ded1; border-radius: var(--radius); color: #075953; }
.notice.failed { background: var(--danger-quiet); color: var(--danger); border-color: #eacaca; }

.login-page, .connecting { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--inset) var(--gutter); }
.connecting { text-align: center; color: var(--muted); }
.login-card { width: min(100%, 375px); padding: clamp(14px, 4vmin, 24px); display: grid; gap: clamp(12px, 3vmin, 20px); background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.login-card h1 { font-size: 24px; }
.login-card form { display: grid; gap: 12px; }
.login-card form label { margin-bottom: -7px; }
.login-card button { width: 100%; }

@container (inline-size >= 62rem) {
  .split { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
}

@container (inline-size < 48rem) {
  .chart-grid {
    --plot-min: 166px;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .sidebar { padding: 8px var(--gutter); border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-block-start: 6px; }
  .sidebar nav a { padding: 7px 4px; font-size: 13px; text-align: center; }
  .topbar { min-height: 43px; padding-block: 4px; }
  h1 { font-size: 22px; }
}

@media (max-width: 500px) {
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar nav a { min-height: 34px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 10px; }
  .stat dd { font-size: 22px; }
  .stat dd.compact-number { font-size: 15px; }
  .filters > label { flex-basis: 110px; }
  .filters > label:has(input[type="datetime-local"]) { flex-basis: 148px; }
  .panel-head { padding: 10px 12px; }
}

@media (max-height: 440px) {
  .sidebar nav { margin-block-start: 6px; }
  .sidebar nav a { padding-block: 5px; }
  .topbar { min-height: 42px; padding-block: 3px; }
}
