:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-muted: #f2f5f3;
  --surface-hover: #f9fbfa;
  --border: #e6ece9;
  --border-strong: #d5dfda;
  --text: #161d1a;
  --text-secondary: #5e6d66;
  --text-muted: #8a9791;
  --accent: #176b56;
  --accent-hover: #125645;
  --accent-soft: #e8f3ef;
  --accent-border: #b8dbd0;
  --good: #16a34a;
  --good-soft: #eaf9ef;
  --warn: #d97706;
  --warn-soft: #fef5e7;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.04), 0 4px 14px rgba(16, 24, 20, 0.03);
  --shadow-lg: 0 14px 40px rgba(15, 23, 20, 0.14);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

[data-palette="teal"] {
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #e6f4f2;
  --accent-border: #99d5ce;
}

[data-palette="slate"] {
  --accent: #1e40af;
  --accent-hover: #1e3a8a;
  --accent-soft: #e8eefc;
  --accent-border: #b3c7f7;
}

[data-theme="dark"] {
  --bg: #0f1412;
  --surface: #171e1b;
  --surface-muted: #1f2824;
  --surface-hover: #222c28;
  --border: #28332e;
  --border-strong: #36443d;
  --text: #edf3f0;
  --text-secondary: #a7b6af;
  --text-muted: #76857e;
  --accent: #2ba483;
  --accent-hover: #35bc97;
  --accent-soft: rgba(43, 164, 131, 0.16);
  --accent-border: rgba(43, 164, 131, 0.36);
  --good-soft: rgba(22, 163, 74, 0.16);
  --warn-soft: rgba(217, 119, 6, 0.18);
  --bad-soft: rgba(220, 38, 38, 0.18);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.tnum {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

button, input, select {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Header */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 32px;
  padding: 0 9px;
  border-radius: 9px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}

.brand-title-wrap {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.clock-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-right: 4px;
}

.icon-btn, .pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.icon-btn {
  width: 36px;
  padding: 0;
  color: var(--text-secondary);
}

.pill-btn {
  padding: 0 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.icon-btn:hover, .pill-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* Main Container */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 20px 44px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* 4-Card Summary Strip */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 16px 12px;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 16px;
  border-right: 1px solid var(--border);
}

.summary-item:last-child {
  border-right: none;
}

.summary-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.summary-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.summary-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.summary-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 3px;
}

/* Cost Estimation Strip */
.cost-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.cost-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cost-title {
  font-weight: 700;
  font-size: 14px;
}

.cost-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.cost-right {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.cost-figure {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.cost-figure .lbl {
  font-size: 13px;
  color: var(--text-secondary);
}

.cost-figure .val {
  font-size: 17px;
  font-weight: 800;
}

.info-circle-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
}

.info-circle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Filter & Control Toolbar */
.filter-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill:hover {
  border-color: var(--accent-border);
}

.filter-pill .cnt {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.filter-pill.active .cnt {
  color: rgba(255, 255, 255, 0.85);
}

.filter-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
}

.filter-pill.active .dot {
  background: #a7f3d0;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 240px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 300px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  font-size: 13.5px;
}

.search-input:focus {
  border-color: var(--accent);
}

.sort-select {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Node Cards Grid */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (min-width: 1180px) {
  .nodes-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.node-card:hover {
  border-color: var(--accent-border);
}

body.compact .node-card {
  padding: 14px 16px 12px;
  gap: 10px;
}

.node-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.node-ident {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.flag-box {
  width: 30px;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-muted);
}

.flag-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.node-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-group-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 2px;
}

.status-pill .sdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-pill.online {
  color: var(--good);
}

.status-pill.online .sdot {
  background: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}

.status-pill.offline {
  color: var(--bad);
}

.status-pill.offline .sdot {
  background: var(--bad);
}

/* Resource Slim Bars */
.res-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.res-row {
  display: grid;
  grid-template-columns: 38px 1fr 42px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.res-label {
  color: var(--text-secondary);
}

.bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.35s ease;
}

.bar-fill.warn {
  background: var(--warn);
}

.bar-fill.bad {
  background: var(--bad);
}

.res-pct {
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

/* Net Speed Split */
.net-split {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 0 2px;
}

.net-side {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.net-arrow {
  color: var(--accent);
  font-weight: 800;
  font-size: 15px;
}

.net-num {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.net-unit {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.net-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

/* Period Traffic Row */
.traffic-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* Latency Metrics Grid inside Card */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 0 -2px;
}

.ping-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  min-height: 44px;
  align-content: start;
}

.ping-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
}

.ping-item:hover {
  background: var(--surface-muted);
}

.ping-name {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ping-val {
  font-weight: 700;
  white-space: nowrap;
}

.ping-val.good { color: var(--good); }
.ping-val.warn { color: var(--warn); }
.ping-val.bad  { color: var(--bad); }
.ping-val.none { color: var(--text-muted); font-weight: 500; }

/* Card Footer */
.node-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.foot-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.os-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.foot-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.detail-link {
  border: none;
  background: transparent;
  padding: 2px 4px;
  color: var(--accent);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
}

.detail-link:hover {
  text-decoration: underline;
}

/* List / Table View */
.table-wrap {
  overflow-x: auto;
}

.node-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.node-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.node-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.node-table tr:last-child td {
  border-bottom: none;
}

.node-table tbody tr:hover {
  background: var(--surface-hover);
  cursor: pointer;
}

/* Chain 204 Telemetry View */
.chains-panel {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chains-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.seg-tabs {
  display: inline-flex;
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.seg-tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.seg-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chain-group-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 4px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chains-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.chain-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chain-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.chain-name {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.3;
}

.chain-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-ok, .badge-warn, .badge-bad {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-ok { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }

.chain-metrics {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.chain-metrics .rtt-big {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.sparkline-svg {
  width: 100%;
  height: 32px;
  display: block;
}

.events-box {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.event-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* Native <dialog> Modals */
dialog.zjm-dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

dialog.zjm-dialog.narrow {
  width: min(460px, calc(100vw - 24px));
}

dialog.zjm-dialog::backdrop {
  background: rgba(15, 23, 20, 0.45);
  backdrop-filter: blur(2px);
}

.dlg-shell {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 36px);
}

.dlg-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dlg-body {
  padding: 18px 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.spec-cell {
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 10px 12px;
}

.spec-cell .k {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.spec-cell .v {
  font-size: 13.5px;
  font-weight: 700;
  word-break: break-word;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.chart-svg {
  width: 100%;
  height: 185px;
  display: block;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.stats-table th, .stats-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.stats-table th:first-child, .stats-table td:first-child {
  text-align: left;
}

/* Login Screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: min(400px, 100%);
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
}

.primary-btn {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.error-banner {
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 600;
}

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

@media (max-width: 820px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .summary-item {
    border-right: none;
    padding: 4px 10px;
  }
  .nodes-grid {
    grid-template-columns: 1fr;
  }
  .topbar-inner {
    padding: 10px 14px;
  }
  .clock-text {
    display: none;
  }
}
