:root {
  --bg: #e9e3d6;
  --paper: #f5efe4;
  --ink: #22302d;
  --muted: #67746e;
  --line: rgba(34, 48, 45, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #ede6d9 0%, #e5ddcf 100%);
  color: var(--ink);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
}

.page-shell {
  width: min(1320px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 14px 0 10px;
  height: 100svh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Header ── */
.masthead {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0 0 4px;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: clamp(1.6rem, 2.6vw, 2.4rem);
  line-height: 1;
}

.headline-meta,
.status-strip,
.page-footer,
.section-note,
.user-item span,
.node-top span,
.metric-bar-top span {
  color: var(--muted);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 0.92rem;
  margin-top: 2px;
}

.status-strip span + span::before {
  content: "·";
  margin-right: 18px;
  color: var(--muted);
}

/* ── Dashboard grid ── */
.dashboard {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "users chart"
    "map   map";
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel-users {
  grid-area: users;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-chart {
  grid-area: chart;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-map {
  grid-area: map;
  overflow-x: auto;
}

.panel-users,
.panel-chart,
.panel-map {
  background: rgba(245, 239, 228, 0.94);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.0rem;
}

.section-note {
  font-size: 0.82rem;
  text-align: right;
}

/* ── Users list ── */
.users-list {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.user-item {
  display: grid;
  gap: 6px;
  align-items: baseline;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.34);
  font-size: 0.88rem;
}

.user-item strong {
  font-size: 0.88rem;
}

.user-bars {
  display: grid;
  gap: 3px;
}

.user-bar {
  height: 8px;
  max-width: 100%;
  border-radius: 999px;
}

.user-bar--actual {
  background: rgba(47, 133, 124, 0.62);
}

.user-bar--reserved {
  background: rgba(180, 130, 40, 0.34);
}

/* ── Chart ── */
.chart-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#utilization-chart {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #efe8da;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(34, 48, 45, 0.88);
  color: #e8e2d8;
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 6px 9px;
  border-radius: 8px;
  white-space: nowrap;
  z-index: 10;
  transform: translateX(-50%);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: middle;
}

/* ── Node map ── */
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 5px;
}

.node-tile {
  padding: 4px 6px 5px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(220, 232, 228, 0.72);
  cursor: default;
}

.node-tile.is-busy {
  background: rgba(42, 126, 118, 0.12);
}

.node-tile.is-bad {
  background: rgba(186, 96, 57, 0.12);
}

.node-top {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 3px;
  font-size: 0.75rem;
}

.node-top span {
  cursor: help;
  font-size: 0.68rem;
}

.node-metrics {
  display: grid;
  gap: 2px;
}

.metric-bar {
  display: grid;
  gap: 1px;
}

.metric-bar-top {
  display: none; /* labels hidden; detail lives in the hover tooltip */
}

.metric-bar-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(34, 48, 45, 0.08);
  overflow: hidden;
}

.metric-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f857c 0%, #56a39a 100%);
}

.metric-bar-fill--cpu {
  background: linear-gradient(90deg, #c35c2e 0%, #de8956 100%);
}

.metric-bar-fill--reserved {
  background: linear-gradient(90deg, rgba(180, 130, 40, 0.55) 0%, rgba(210, 165, 60, 0.55) 100%);
}

.metric-bar-fill--load {
  background: linear-gradient(90deg, rgba(91, 92, 143, 0.5) 0%, rgba(125, 126, 183, 0.7) 100%);
}

.node-tile.is-bad .metric-bar-fill {
  background: linear-gradient(90deg, #b55d38 0%, #d78a62 100%);
}

.node-tile.is-bad .metric-bar-fill--reserved {
  background: linear-gradient(90deg, rgba(181, 93, 56, 0.45) 0%, rgba(215, 138, 98, 0.45) 100%);
}

.node-tile.is-bad .metric-bar-fill--load {
  background: linear-gradient(90deg, rgba(181, 93, 56, 0.4) 0%, rgba(215, 138, 98, 0.55) 100%);
}

.empty-copy {
  color: var(--muted);
  padding: 6px 0;
  font-size: 0.88rem;
}

/* ── Footer ── */
.page-footer {
  display: flex;
  gap: 14px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 0.80rem;
  color: var(--muted);
}

.page-footer a { color: inherit; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .page-shell {
    height: auto;
    min-height: 100svh;
  }

  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "users"
      "chart"
      "map";
    flex: 0 0 auto;
  }

  .panel-users,
  .panel-chart {
    overflow: visible;
  }

  .users-list {
    overflow: visible;
  }

  .chart-wrap {
    min-height: 220px;
  }
}

@media (max-height: 720px) and (orientation: landscape) {
  .page-shell {
    height: auto;
    min-height: 100svh;
  }

  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "users"
      "chart"
      "map";
    flex: 0 0 auto;
  }

  .panel-users,
  .panel-chart {
    overflow: visible;
  }

  .users-list {
    overflow: visible;
  }

  .chart-wrap {
    min-height: 180px;
  }
}

@media (max-width: 700px) {
  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
