:root {
  --cf-orange: #f6821f;
  --cf-orange-dark: #e06d0b;
  --cf-blue: #0051c3;
  --cf-blue-light: #2c7be5;
  --cf-blue-bg: #edf4ff;
  --cf-green: #107c41;
  --cf-green-bg: #e6f4ea;
  --cf-amber: #b25e09;
  --cf-amber-bg: #fef3e2;
  --cf-red: #c5221f;
  --cf-red-bg: #fce8e6;

  --bg-page: #f7f8fa;
  --bg-surface: #ffffff;
  --bg-subtle: #fbfcfd;
  --border: #d9dee7;
  --border-light: #eaedf2;

  --text-primary: #1d2430;
  --text-secondary: #4e5969;
  --text-muted: #768396;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--cf-blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: #f1f3f7;
  padding: 1px 5px;
  border-radius: 3px;
  color: #313a46;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  font-family: inherit;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}
.btn-block {
  width: 100%;
  height: 38px;
  font-size: 14px;
}
.btn-primary {
  background: var(--cf-blue);
  color: #fff;
  border-color: var(--cf-blue);
}
.btn-primary:hover:not(:disabled) {
  background: #0043a4;
}
.btn-default {
  background: #fff;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-default:hover:not(:disabled) {
  background: #f3f5f8;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: #f0f2f6;
  color: var(--text-primary);
}

/* Brand Lockup */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.cf-bar {
  display: inline-block;
  width: 10px;
  height: 20px;
  background: var(--cf-orange);
  border-radius: 2px;
}
.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  color: var(--text-primary);
}

/* Login View */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f7f8fa;
}
.login-topbar {
  height: 54px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ext-link {
  font-size: 12px;
  color: var(--text-secondary);
}
.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  width: 100%;
  max-width: 410px;
  background: #fff;
  border: 1px solid var(--border);
  border-top: 3px solid var(--cf-orange);
  border-radius: 6px;
  padding: 28px 30px 24px;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.04);
}
.zone-chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f2f4f8;
  border: 1px solid var(--border-light);
  padding: 2px 8px;
  border-radius: 3px;
  margin-bottom: 10px;
}
.login-box__header h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
}
.login-box__header p {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 13px;
}
.form-field {
  margin-bottom: 16px;
}
.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.form-field input {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: #fff;
}
.form-field input:focus {
  outline: none;
  border-color: var(--cf-blue);
  box-shadow: 0 0 0 2px rgba(0, 81, 195, 0.14);
}
.form-error {
  margin-bottom: 14px;
  padding: 9px 11px;
  border-radius: 4px;
  background: var(--cf-red-bg);
  border: 1px solid #f5c2c0;
  color: var(--cf-red);
  font-size: 12px;
}
.login-box__footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Console Layout */
.console-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar__left, .topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.crumb-sep {
  color: #c0c8d4;
  font-size: 16px;
}
.zone-selector {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.zone-name {
  font-weight: 600;
  font-size: 13px;
}
.zone-plan {
  font-size: 11px;
  color: var(--text-secondary);
  background: #e9eef6;
  padding: 1px 6px;
  border-radius: 3px;
}
.refresh-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
#last-updated-text {
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}
.divider-v {
  width: 1px;
  height: 20px;
  background: var(--border);
}
.admin-account {
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--cf-orange-dark);
  background: #fff3e8;
  border: 1px solid #ffd8b5;
  padding: 1px 6px;
  border-radius: 3px;
}
.admin-uname {
  font-weight: 600;
}

.console-body {
  flex: 1;
  display: flex;
  min-height: calc(100vh - 52px);
}

/* Sidebar */
.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.sidebar__group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 0 10px 8px;
}
.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}
.nav-item:hover {
  background: #f4f6f9;
  color: var(--text-primary);
}
.nav-item.is-active {
  background: var(--cf-blue-bg);
  color: var(--cf-blue);
  border-left-color: var(--cf-blue);
  font-weight: 600;
}
.nav-counter {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: #eef2f7;
  color: var(--text-secondary);
}
.nav-item.is-active .nav-counter {
  background: #d5e6ff;
  color: var(--cf-blue);
}
.sidebar__footer {
  margin-top: 24px;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.quick-links-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.quick-link {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Content Area */
.content {
  flex: 1;
  min-width: 0;
  max-width: 1440px;
  padding: 22px 28px 40px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}
.page-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Segmented Time Control */
.segmented-control {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.seg-btn {
  border: none;
  border-right: 1px solid var(--border);
  background: #fff;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.seg-btn:last-child {
  border-right: none;
}
.seg-btn:hover {
  background: #f5f7fa;
}
.seg-btn.is-active {
  background: var(--cf-blue);
  color: #fff;
}

.alert-banner {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--cf-red-bg);
  border: 1px solid #f3b7b4;
  color: var(--cf-red);
  border-radius: 4px;
  font-size: 12px;
}

/* Cloudflare Style KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 18px;
  overflow: hidden;
}
.kpi-strip--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.kpi-cell {
  padding: 16px 18px;
  border-right: 1px solid var(--border-light);
  transition: background 0.12s ease;
}
.kpi-cell[data-tip] {
  cursor: default;
}
.kpi-cell:hover {
  background: #fbfdff;
}
.kpi-cell:last-child {
  border-right: none;
}
.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.kpi-sub strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* Cards & Grids */
.grid-2col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.cf-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 18px;
  overflow: hidden;
}
.grid-2col > .cf-card {
  margin-bottom: 0;
}
.cf-card__header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.cf-card__title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.cf-card__meta {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.cf-card__body {
  padding: 16px 18px;
}
.link-btn {
  border: none;
  background: none;
  color: var(--cf-blue);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.link-btn:hover {
  text-decoration: underline;
}

/* Per-card header controls & Cloudflare compact range pills */
.card-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card-range {
  display: inline-flex;
  align-items: center;
  background: #f4f6f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
  gap: 1px;
}
.card-range button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 7px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.25;
  transition: background 0.12s ease, color 0.12s ease;
}
.card-range button:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.7);
}
.card-range button.is-active {
  background: #ffffff;
  color: var(--cf-blue);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}
.cf-card.is-loading {
  opacity: 0.72;
  transition: opacity 0.15s ease;
}

/* Chart Legend & SVG */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.swatch--blue { background: var(--cf-blue-light); }
.swatch--orange { background: var(--cf-orange); }
.swatch--green { background: var(--cf-green); }
.swatch--amber { background: #e69d00; }
.swatch--red { background: var(--cf-red); }

.svg-chart-wrap {
  width: 100%;
  height: 224px;
  position: relative;
  user-select: none;
}
.svg-chart-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.chart-empty {
  height: 224px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* Interactive Cloudflare-style Chart & Metric Tooltip */
.cf-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: rgba(24, 30, 41, 0.96);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.22);
  min-width: 168px;
  max-width: 280px;
  font-variant-numeric: tabular-nums;
}
.cf-tooltip__title {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: #cbd5e1;
  padding-bottom: 5px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.cf-tooltip__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 3px;
}
.cf-tooltip__key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #e2e8f0;
}
.cf-tooltip__dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}
.cf-tooltip__val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #ffffff;
}
.cf-tooltip__desc {
  color: #e2e8f0;
  font-size: 12px;
}

.dist-row {
  margin-bottom: 9px;
  padding: 4px 6px;
  margin-left: -6px;
  margin-right: -6px;
  border-radius: 4px;
  transition: background 0.12s ease;
}
.dist-row:hover {
  background: #f5f8fc;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.cf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.cf-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
.cf-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}
.cf-table tbody tr:last-child td {
  border-bottom: none;
}
.cf-table tbody tr:hover td {
  background: #f9fbff;
}
.cf-table th.num, .cf-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}
.muted {
  color: var(--text-muted);
}
.empty-row {
  text-align: center;
  color: var(--text-muted) !important;
  padding: 24px 14px !important;
}

/* Status Dots & Pills */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa5b4;
}
.status-dot--ok { background: #16a34a; }
.status-dot--idle { background: #f59e0b; }
.status-dot--off { background: #cbd5e1; }
.status-dot--err { background: #dc2626; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill--ok { background: var(--cf-green-bg); color: var(--cf-green); }
.pill--warn { background: var(--cf-amber-bg); color: var(--cf-amber); }
.pill--err { background: var(--cf-red-bg); color: var(--cf-red); }
.pill--blue { background: var(--cf-blue-bg); color: var(--cf-blue); }
.pill--neutral { background: #eef1f6; color: #525f73; }

/* Distribution Bars */
.split-bars {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.dist-group__title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 10px;
}
.dist-row__head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}
.dist-bar-bg {
  height: 6px;
  background: #edf0f5;
  border-radius: 3px;
  overflow: hidden;
}
.dist-bar-fill {
  height: 100%;
  background: var(--cf-blue-light);
  border-radius: 3px;
}
.dist-bar-fill--green { background: var(--cf-green); }
.dist-bar-fill--orange { background: var(--cf-orange); }

/* System Nodes Grid */
.nodes-grid {
  padding: 16px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.node-box {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 14px 16px;
  background: var(--bg-subtle);
}
.node-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.node-box__name {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 13px;
}
.node-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  font-size: 12px;
}
.node-metric-label {
  color: var(--text-muted);
  font-size: 11px;
}
.node-metric-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.meter {
  margin-top: 4px;
  height: 5px;
  background: #e5e9f0;
  border-radius: 3px;
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  background: var(--cf-blue-light);
}

@media (max-width: 1120px) {
  .kpi-strip, .kpi-strip--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi-cell {
    border-bottom: 1px solid var(--border-light);
  }
  .grid-2col, .split-bars {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .console-body {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
  }
  .sidebar__nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .nav-item {
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: 4px;
    white-space: nowrap;
    width: auto;
  }
  .nav-item.is-active {
    border-bottom-color: var(--cf-blue);
  }
  .sidebar__footer, .sidebar__group-label {
    display: none;
  }
  .content {
    padding: 16px;
  }
}
