:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-soft: #f8f9fa;
  --text: #1e252b;
  --muted: #66727c;
  --line: #dfe4e7;
  --line-strong: #cbd3d8;
  --green: #16885b;
  --green-soft: #e7f5ef;
  --red: #c44147;
  --red-soft: #fbecee;
  --amber: #a56a12;
  --amber-soft: #fff4dd;
  --blue: #286f9e;
  --focus: #5c98bd;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, input, select, textarea { border-radius: 6px; }
button { min-height: 38px; border: 1px solid transparent; padding: 0 15px; cursor: pointer; font-weight: 650; }
button:disabled { cursor: wait; opacity: .6; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 34%, transparent); outline-offset: 1px; }
button.primary { background: var(--text); color: white; }
button.primary:hover { background: #343c43; }
button.quiet { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
button.quiet:hover { background: var(--surface-soft); }
button.danger { background: transparent; color: var(--red); border-color: #edc7ca; min-height: 32px; padding: 0 10px; }
button.danger:hover { background: var(--red-soft); }
button.revoke { background: transparent; color: var(--amber); border-color: #ead19e; min-height: 32px; padding: 0 10px; }
button.revoke:hover { background: var(--amber-soft); }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f2; }
.login-panel { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 34px; box-shadow: 0 14px 40px rgba(24, 34, 41, .09); }
.login-panel h1 { margin: 22px 0 6px; font-size: 25px; }
.login-panel p { color: var(--muted); margin: 0 0 24px; }
.login-panel form { display: grid; gap: 9px; }
.login-panel button { margin-top: 8px; }
label { display: block; margin: 0 0 7px; color: #48535c; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); padding: 10px 11px; }
textarea { resize: vertical; font-family: Consolas, "SFMono-Regular", monospace; font-size: 13px; line-height: 1.55; }
.form-error { min-height: 20px; margin-top: 10px; color: var(--red); font-size: 13px; }

.brand-mark { display: flex; height: 32px; align-items: flex-end; gap: 5px; }
.brand-mark span { width: 9px; display: block; border-radius: 3px 3px 1px 1px; }
.brand-mark span:nth-child(1) { height: 15px; background: var(--green); }
.brand-mark span:nth-child(2) { height: 23px; background: #d49a32; }
.brand-mark span:nth-child(3) { height: 31px; background: var(--blue); }
.brand-mark.small { height: 26px; gap: 4px; }
.brand-mark.small span { width: 7px; }
.brand-mark.small span:nth-child(1) { height: 12px; }
.brand-mark.small span:nth-child(2) { height: 19px; }
.brand-mark.small span:nth-child(3) { height: 26px; }

.app-view { min-height: 100vh; }
.topbar { height: 66px; padding: 0 max(22px, calc((100vw - 1280px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 2px; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
.workspace { width: min(1280px, calc(100% - 44px)); margin: 0 auto; padding: 28px 0 60px; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; margin-bottom: 26px; }
.summary-item { min-height: 96px; display: flex; flex-direction: column; justify-content: center; padding: 18px 22px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item span { color: var(--muted); font-size: 13px; }
.summary-item strong { font-size: 28px; margin-top: 5px; }
.summary-item.online strong { color: var(--green); }
.summary-item.offline strong { color: var(--red); }
.summary-item.revoked strong { color: var(--amber); }

.node-section { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; padding: 21px 22px; border-bottom: 1px solid var(--line); }
.section-head h1 { margin: 0 0 4px; font-size: 19px; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; }
.search-field { width: min(280px, 100%); margin: 0; }
.search-field span { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.search-field input { padding: 8px 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { padding: 14px 13px; text-align: left; border-bottom: 1px solid #edf0f1; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-soft); font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfb; }
.node-main strong, .node-main span { display: block; }
.node-main strong { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-main span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; min-width: 64px; font-weight: 650; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.status-pill.online { color: var(--green); }
.status-pill.online::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-pill.revoked { color: var(--amber); }
.status-pill.revoked::before { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.meter-cell { min-width: 112px; }
.meter-value { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px; }
.meter-track { width: 100%; height: 5px; background: #e8ecee; border-radius: 2px; overflow: hidden; }
.meter-track span { display: block; height: 100%; background: var(--blue); border-radius: inherit; }
.memory .meter-track span { background: #8a6db1; }
.gauge-cell { min-width: 124px; width: 132px; padding: 4px 8px; border-radius: 4px; }
.gauge-cell.cpu { background: #fff0f0; }
.gauge-cell.memory { background: #eff9f3; }
.gauge-cell.disk { background: #edfafd; }
.gauge { position: relative; width: 112px; height: 67px; margin: 0 auto; overflow: hidden; }
.gauge::before { content: ""; position: absolute; inset: 0 auto auto 0; width: 112px; height: 112px; border-radius: 50%; background: conic-gradient(from 270deg, var(--gauge-color) 0deg var(--gauge-value), var(--gauge-track) var(--gauge-value) 180deg, transparent 180deg 360deg); }
.gauge::after { content: ""; position: absolute; top: 10px; left: 10px; width: 92px; height: 92px; border-radius: 50%; background: var(--surface); }
.gauge-value { position: absolute; z-index: 1; left: 0; right: 0; bottom: 4px; text-align: center; color: var(--text); font-family: Georgia, serif; font-size: 16px; font-weight: 700; }
.gauge-cell.cpu { --gauge-color: #e9aab0; --gauge-track: #e7d6d8; }
.gauge-cell.memory { --gauge-color: #19ae79; --gauge-track: #c8e7d8; }
.gauge-cell.disk { --gauge-color: #10b6d1; --gauge-track: #c6e7ed; }
.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions-column { text-align: right; }
.empty-state { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 8px; }
.empty-state strong { color: var(--text); font-size: 16px; }
.node-cards { display: none; }

.dialog { width: min(640px, calc(100% - 30px)); border: 0; padding: 0; border-radius: 8px; color: var(--text); box-shadow: 0 26px 80px rgba(16, 26, 32, .25); }
.dialog::backdrop { background: rgba(24, 31, 36, .54); }
.dialog-shell { padding: 0; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; padding: 22px 24px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0 0 4px; font-size: 20px; }
.dialog-head p { margin: 0; color: var(--muted); font-size: 13px; }
.close-btn { width: 36px; min-height: 36px; padding: 0; background: transparent; border-color: var(--line); color: var(--muted); font-size: 24px; line-height: 1; }
#enrollFormView, #commandView { padding: 22px 24px 24px; }
#enrollFormView input, #enrollFormView select { margin-bottom: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.command-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.command-tabs { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin-bottom: 15px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 7px; }
.command-tabs button { min-height: 32px; padding: 0 14px; background: transparent; color: var(--muted); }
.command-tabs button.active { background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: 0 1px 2px rgba(20, 30, 36, .06); }
#copyStatus { color: var(--green); }
.warning { padding: 10px 12px; margin-bottom: 15px; background: var(--amber-soft); border: 1px solid #efd49c; border-radius: 6px; color: #81520e; }
#dialogError { padding: 0 24px 8px; }
.settings-dialog { width: min(720px, calc(100% - 30px)); }
.settings-body { max-height: calc(100vh - 110px); overflow-y: auto; padding: 0 24px 22px; }
.settings-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.settings-section-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.settings-section-head small { color: var(--muted); font-weight: 400; }
.settings-section > label:not(.check-row) { margin-top: 14px; }
.check-row { display: flex; align-items: flex-start; gap: 11px; margin: 0; cursor: pointer; }
.check-row input { flex: 0 0 auto; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--green); }
.check-row span, .check-row strong, .check-row small { display: block; }
.check-row strong { color: var(--text); }
.check-row small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; gap: 18px; margin-top: 17px; }
.settings-grid label { margin: 0; }
.settings-grid select { margin-top: 7px; }
.check-row.compact { min-height: 41px; align-items: center; }
.settings-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 20px; }
.settings-actions > div { display: flex; gap: 8px; }
.compact-actions { justify-content: flex-start; margin-top: 14px; }
#alertsStatus { color: var(--green); font-size: 13px; }
#alertsError { margin-top: 8px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 40; max-width: min(360px, calc(100% - 44px)); padding: 11px 14px; background: #20272c; color: white; border-radius: 6px; box-shadow: 0 8px 28px rgba(0, 0, 0, .18); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 68px; padding: 12px 15px; align-items: stretch; flex-direction: column; gap: 11px; }
  .brand { margin: 0; }
  .top-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; }
  .top-actions button { width: 100%; min-height: 36px; padding: 0 8px; }
  .workspace { width: calc(100% - 24px); padding-top: 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
  .summary-item { min-height: 80px; padding: 14px 16px; }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .summary-item strong { font-size: 24px; }
  .section-head { align-items: stretch; flex-direction: column; gap: 15px; padding: 18px 16px; }
  .search-field { width: 100%; }
  .table-wrap { display: none; }
  .node-cards { display: grid; gap: 0; }
  .node-card { padding: 17px 16px; border-bottom: 1px solid var(--line); }
  .node-card:last-child { border-bottom: 0; }
  .node-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
  .node-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
  .node-card-grid > div > span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 5px; }
  .node-card .row-actions { justify-content: flex-start; margin-top: 16px; }
  .login-panel { padding: 28px 22px; }
  .dialog-actions { flex-direction: column; }
  .dialog-actions button { width: 100%; }
  .command-meta { flex-direction: column; }
  .settings-body { padding: 0 17px 18px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-actions { align-items: stretch; flex-direction: column; }
  .settings-actions > div { display: grid; grid-template-columns: 1fr 1fr; }
  .settings-actions button { width: 100%; padding: 0 8px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #161a1d;
    --surface: #20252a;
    --surface-soft: #252b30;
    --text: #edf1f3;
    --muted: #a3adb5;
    --line: #343b41;
    --line-strong: #475058;
    --green: #58c493;
    --green-soft: #203d32;
    --red: #ef7c81;
    --red-soft: #422a2d;
    --amber: #e6b75e;
    --amber-soft: #46391f;
    --blue: #6db1dc;
  }
  .login-view { background: #171b1e; }
  button.primary { background: #e5eaed; color: #20252a; }
  button.primary:hover { background: white; }
  tbody tr:hover { background: #242a2f; }
  th, td { border-bottom-color: #30373c; }
  .meter-track { background: #343c42; }
  .toast { background: #edf1f3; color: #1f252a; }
}
