/* 首页实时资源监控：只承载组件令牌和布局，不修改业务卡片样式。 */

.home-resource-open-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 8px);
  min-height: 36px;
  padding: 0 var(--space-4, 16px);
  border: 1px solid var(--primary-200);
  border-radius: var(--radius-full, 9999px);
  background: var(--primary-50);
  color: var(--primary-700);
  cursor: pointer;
  font: inherit;
  font-size: var(--font-size-sm, 14px);
  transition: transform var(--transition-fast, 150ms ease), box-shadow var(--transition-fast, 150ms ease), background var(--transition-fast, 150ms ease);
}

.home-resource-open-btn:hover {
  transform: translateY(-1px);
  background: var(--primary-100);
  box-shadow: var(--shadow-sm);
}

.home-resource-modal {
  --modal-width: 760px;
  --modal-max-height: calc(100dvh - 32px);
  width: min(760px, calc(100vw - 32px));
  max-width: 760px;
  max-width: min(760px, calc(100vw - 32px));
  height: auto;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
}

.home-resource-modal--overview {
  --modal-width: 1600px;
  --modal-max-height: min(900px, calc(100dvh - 32px));
  width: min(1600px, calc(100vw - 32px));
  max-width: min(1600px, calc(100vw - 32px));
  height: auto;
  max-height: min(900px, calc(100dvh - 32px));
}

/* 首页资源弹窗需抵御工作台的全局 modal 尺寸规则及 !important 兼容覆盖。 */
#homeResourceMonitor > .modal {
  --modal-width: 1600px !important;
  width: min(1600px, calc(100vw - 32px)) !important;
  max-width: min(1600px, calc(100vw - 32px)) !important;
}

.home-resource-modal--chart {
  --modal-width: 860px;
  --modal-height: min(620px, calc(100dvh - 48px));
  width: min(860px, calc(100vw - 32px));
  max-width: min(860px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 48px));
  height: min(620px, calc(100dvh - 48px));
}

.home-resource-modal--params {
  --modal-width: 540px;
  --modal-max-height: min(560px, calc(100dvh - 32px));
  width: min(540px, calc(100vw - 32px));
  max-width: min(540px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 32px));
  max-height: min(560px, calc(100dvh - 32px));
}

.home-resource-modal .modal-body {
  padding: var(--space-5, 20px);
  background: var(--bg-secondary);
}

.home-resource-modal--overview .modal-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.resource-overview {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  grid-template-areas:
    'meta meta'
    'system network'
    'storage network';
  align-content: start;
  gap: var(--space-5, 20px) var(--space-6, 24px);
}

.resource-overview__meta {
  grid-area: meta;
  min-height: 28px;
}

.resource-section--system {
  grid-area: system;
}

.resource-section--storage {
  grid-area: storage;
}

.resource-section--network {
  grid-area: network;
  align-content: start;
}

.resource-section {
  display: grid;
  gap: var(--space-3, 12px);
  min-width: 0;
}

.resource-section__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
}

.resource-section__title {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--font-size-md, 16px);
  font-weight: var(--font-weight-semibold, 600);
}

.resource-section__status {
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
}

.resource-section__status.is-error {
  color: var(--danger);
}

.resource-overview__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  color: var(--text-secondary);
  font-size: var(--font-size-xs, 12px);
}

.resource-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3, 12px);
}

.resource-summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.resource-metric-card {
  min-width: 0;
  padding: var(--space-4, 16px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 12px);
  background: var(--bg-primary);
  box-shadow: var(--shadow-sm);
}

button.resource-metric-card {
  width: 100%;
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform var(--transition-fast, 150ms ease), border-color var(--transition-fast, 150ms ease), box-shadow var(--transition-fast, 150ms ease);
}

button.resource-metric-card:hover {
  transform: translateY(-1px);
  border-color: var(--primary-300);
  box-shadow: var(--shadow-md);
}

.resource-metric-card__label {
  color: var(--text-secondary);
  font-size: var(--font-size-xs, 12px);
}

.resource-metric-card__value {
  display: block;
  margin-top: var(--space-2, 8px);
  color: var(--text-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-2xl, 24px);
  font-weight: var(--font-weight-bold, 700);
}

.resource-metric-card__hint {
  display: block;
  margin-top: var(--space-1, 4px);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
}

.resource-disk-grid,
.resource-interface-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3, 12px);
  min-width: 0;
}

.resource-disk-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}

.resource-disk-card,
.resource-interface-card {
  min-width: 0;
  padding: var(--space-4, 16px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 12px);
  background: var(--bg-primary);
}

.resource-disk-card__heading,
.resource-interface-card__heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  color: var(--text-primary);
}

.resource-disk-card__percent,
.resource-interface-card__heading > span {
  color: var(--text-secondary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm, 14px);
  white-space: nowrap;
}

.resource-progress__bar {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: var(--space-3, 12px);
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-full, 9999px);
  appearance: none;
  background: var(--border-light);
  color: var(--primary-500);
}

.resource-progress__bar::-webkit-progress-bar {
  border-radius: inherit;
  background: var(--border-light);
}

.resource-progress__bar::-webkit-progress-value {
  border-radius: inherit;
  background: var(--primary-500);
}

.resource-progress__bar::-moz-progress-bar {
  border-radius: inherit;
  background: var(--primary-500);
}

.resource-disk-card--warning .resource-progress__bar::-webkit-progress-value {
  background: var(--warning);
}

.resource-disk-card--warning .resource-progress__bar::-moz-progress-bar {
  background: var(--warning);
}

.resource-disk-card--danger .resource-progress__bar::-webkit-progress-value {
  background: var(--danger);
}

.resource-disk-card--danger .resource-progress__bar::-moz-progress-bar {
  background: var(--danger);
}

.resource-disk-card__details,
.resource-interface-card__counters {
  margin: var(--space-2, 8px) 0 0;
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
  line-height: var(--line-height-normal, 1.5);
  overflow-wrap: anywhere;
}

.resource-traffic-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3, 12px);
}

.resource-traffic-totals > div {
  display: grid;
  gap: var(--space-1, 4px);
  min-width: 0;
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md, 8px);
  background: var(--bg-primary);
}

.resource-traffic-totals > div > span {
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
}

.resource-traffic-totals > div > strong {
  color: var(--text-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-lg, 18px);
  overflow-wrap: anywhere;
}

.resource-traffic-totals .resource-traffic-capacity {
  grid-column: 1 / -1;
  display: block;
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
}

.resource-interface-card__rates {
  display: grid;
  gap: var(--space-2, 8px);
  margin-top: var(--space-3, 12px);
}

.resource-interface-card__rate {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-2, 8px);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
}

.resource-interface-card__rate strong {
  color: var(--text-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm, 14px);
  overflow-wrap: anywhere;
}

.resource-interface-card__rate > span:last-child {
  text-align: right;
  white-space: nowrap;
}

.resource-empty-state {
  grid-column: 1 / -1;
  padding: var(--space-4, 16px);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-lg, 12px);
  color: var(--text-tertiary);
  font-size: var(--font-size-sm, 14px);
  text-align: center;
}

.resource-monitor-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 8px);
}

.resource-monitor-status::before {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full, 9999px);
  background: var(--success);
  content: '';
}

.resource-monitor-status.is-error::before {
  background: var(--danger);
}

.resource-chart-shell {
  display: grid;
  gap: var(--space-4, 16px);
}

.resource-chart-header,
.resource-chart-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
}

.resource-chart-current {
  color: var(--primary-700);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-3xl, 30px);
  font-weight: var(--font-weight-bold, 700);
}

.resource-chart {
  display: block;
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 12px);
  background: var(--bg-primary);
}

.resource-chart__line {
  fill: none;
  stroke: var(--primary-500);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.resource-chart__area {
  fill: var(--primary-100);
  opacity: .65;
}

.resource-chart__grid {
  stroke: var(--border-light);
  stroke-width: 1;
}

.resource-detail-list {
  display: grid;
  gap: var(--space-3, 12px);
  margin: 0;
}

.resource-detail-row {
  display: grid;
  grid-template-columns: minmax(110px, .8fr) minmax(0, 1.2fr);
  gap: var(--space-4, 16px);
  padding-bottom: var(--space-3, 12px);
  border-bottom: 1px solid var(--border-light);
}

.resource-detail-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.resource-detail-row dt {
  color: var(--text-secondary);
}

.resource-detail-row dd {
  margin: 0;
  color: var(--text-primary);
  font-family: var(--font-family-mono);
  overflow-wrap: anywhere;
}

.resource-modal-note {
  margin: 0;
  color: var(--text-tertiary);
  font-size: var(--font-size-xs, 12px);
  line-height: var(--line-height-normal, 1.5);
}

@media (max-width: 1023px) {
  .resource-overview {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'meta'
      'system'
      'storage'
      'network';
    gap: var(--space-5, 20px);
  }

  .home-resource-modal--overview {
    width: min(980px, calc(100vw - 32px));
    max-width: min(980px, calc(100vw - 32px));
    height: auto;
    max-height: min(900px, calc(100dvh - 32px));
  }

  #homeResourceMonitor > .modal {
    --modal-width: 980px !important;
    width: min(980px, calc(100vw - 32px)) !important;
    max-width: min(980px, calc(100vw - 32px)) !important;
  }
}

@media (max-width: 640px) {
  #homeResourceMonitor.modal-overlay--responsive {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .home-resource-modal,
  .home-resource-modal--chart,
  .home-resource-modal--params {
    width: calc(100vw - 16px);
    max-width: none;
    height: auto;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
  }

  .home-resource-modal--overview {
    width: calc(100vw - 16px);
    max-width: none;
    height: min(900px, calc(100dvh - 32px));
    max-height: min(900px, calc(100dvh - 32px));
    border-radius: var(--m-radius-sheet, 14px);
  }

  #homeResourceMonitor > .modal {
    --modal-width: calc(100vw - 16px) !important;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
  }

  .home-resource-modal--overview > .modal-header {
    padding: var(--m-space-3, 12px) var(--m-space-4, 16px);
  }

  .home-resource-modal--overview .modal-close {
    width: var(--m-touch-target, 44px);
    min-width: var(--m-touch-target, 44px);
    height: var(--m-touch-target, 44px);
    min-height: var(--m-touch-target, 44px);
  }

  .home-resource-open-btn {
    width: 100%;
    justify-content: center;
  }

  .resource-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .resource-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .resource-disk-grid,
  .resource-interface-list {
    grid-template-columns: 1fr;
  }

  .home-resource-modal .modal-body {
    padding: var(--m-space-4, 16px);
    background: var(--m-bg);
    color: var(--m-text);
  }

  .resource-section__title {
    color: var(--m-text);
  }

  .resource-section__status,
  .resource-metric-card__label,
  .resource-metric-card__hint,
  .resource-disk-card__details,
  .resource-interface-card__counters,
  .resource-traffic-totals > div > span,
  .resource-interface-card__rate {
    color: var(--m-text-2);
  }

  .resource-metric-card,
  .resource-disk-card,
  .resource-interface-card,
  .resource-traffic-totals > div {
    border-color: var(--m-border);
    background: var(--m-surface);
  }

  .resource-metric-card__value,
  .resource-disk-card__heading,
  .resource-interface-card__heading,
  .resource-interface-card__rate strong,
  .resource-traffic-totals > div > strong {
    color: var(--m-text);
  }

  .resource-modal-note,
  .resource-traffic-capacity,
  .resource-empty-state {
    color: var(--m-text-3);
  }

  .resource-progress__bar {
    color: var(--m-primary);
  }

  .resource-progress__bar::-webkit-progress-bar {
    background: var(--m-border);
  }

  .resource-progress__bar::-webkit-progress-value {
    background: var(--m-primary);
  }

  .resource-progress__bar::-moz-progress-bar {
    background: var(--m-primary);
  }

  .resource-disk-card--warning .resource-progress__bar::-webkit-progress-value {
    background: var(--m-warning);
  }

  .resource-disk-card--warning .resource-progress__bar::-moz-progress-bar {
    background: var(--m-warning);
  }

  .resource-disk-card--danger .resource-progress__bar::-webkit-progress-value {
    background: var(--m-danger);
  }

  .resource-disk-card--danger .resource-progress__bar::-moz-progress-bar {
    background: var(--m-danger);
  }

  .resource-monitor-status::before {
    background: var(--m-success);
  }

  .resource-monitor-status.is-error::before {
    background: var(--m-danger);
  }

  .resource-empty-state {
    border-color: var(--m-border);
  }

  .resource-chart-header,
  .resource-chart-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .resource-detail-row {
    grid-template-columns: 1fr;
    gap: var(--space-1, 4px);
  }

  .resource-interface-card__rate {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .resource-interface-card__rate > span:last-child {
    grid-column: 2;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-resource-open-btn,
  button.resource-metric-card {
    transition: none;
  }

  .home-resource-open-btn:hover,
  button.resource-metric-card:hover {
    transform: none;
  }
}
