:root {
  /* 色と陰影は監視状態が見分けやすいように用途別トークンへ分けます。 */
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #080b10;
  --panel: rgba(19, 24, 32, 0.82);
  --panel-strong: #151b24;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef4ff;
  --muted: #8997aa;
  --soft: #c7d2e1;
  --blue: #59a6ff;
  --green: #39d98a;
  --orange: #ffb454;
  --red: #ff6b6b;
  --violet: #a98bff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  /* モバイルを基準に、背景だけ軽い奥行きを持たせます。 */
  background:
    radial-gradient(circle at top left, rgba(89, 166, 255, 0.18), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(57, 217, 138, 0.13), transparent 24rem),
    linear-gradient(135deg, #080b10 0%, #0f151d 48%, #111820 100%);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
p,
dl,
dd {
  margin: 0;
}

.app-frame {
  /* 初期状態はスマホ向けの1カラムです。 */
  display: grid;
  min-height: 100vh;
}

.sidebar,
.dashboard {
  padding: 16px;
}

.sidebar {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 14px;
}

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

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, #59a6ff, #39d98a);
  border-radius: 8px;
  color: #061018;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand h1 {
  font-size: 17px;
  letter-spacing: 0;
  line-height: 1.2;
}

.brand p,
.eyebrow,
.metric-card span,
.metric-card small,
.usage-list dt,
.event-meta {
  color: var(--muted);
}

.brand p {
  font-size: 12px;
  margin-top: 3px;
}

.agent-card,
.panel,
.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.agent-card {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 84px;
  padding: 14px;
}

.eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.agent-card strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
  margin-top: 8px;
}

.health-dot {
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
  height: 14px;
  width: 14px;
}

.health-dot.idle {
  background: #6b7280;
  box-shadow: 0 0 0 7px rgba(107, 114, 128, 0.12);
}

.health-dot.live {
  background: var(--blue);
  box-shadow: 0 0 0 7px rgba(89, 166, 255, 0.14), 0 0 22px rgba(89, 166, 255, 0.42);
}

.health-dot.stable {
  background: var(--green);
  box-shadow: 0 0 0 7px rgba(57, 217, 138, 0.14);
}

.health-dot.alert {
  background: var(--red);
  box-shadow: 0 0 0 7px rgba(255, 107, 107, 0.14), 0 0 22px rgba(255, 107, 107, 0.4);
}

.side-nav {
  /* モバイルではナビを横並びにして縦スクロールを増やしません。 */
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.side-nav a {
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--soft);
  min-height: 40px;
  overflow: hidden;
  padding: 10px 8px;
  text-align: center;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav a:hover,
.side-nav a.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
  color: var(--text);
}

.dashboard {
  display: grid;
  gap: 16px;
}

.hero {
  display: grid;
  gap: 14px;
}

.hero h2 {
  font-size: 34px;
  line-height: 1;
  margin-top: 10px;
  max-width: 820px;
}

.toolbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 8px;
  width: 100%;
}

#last-updated {
  color: var(--muted);
  font-size: 13px;
  min-width: 76px;
}

#refresh {
  align-items: center;
  background: #eef4ff;
  border: 0;
  border-radius: 8px;
  color: #071019;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 900;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.logout-button {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--soft);
  min-height: 38px;
  padding: 0 12px;
}

.metrics {
  /* KPIはスマホで1列、広い画面で段階的に増やします。 */
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.metric-card {
  min-height: 128px;
  overflow: hidden;
  padding: 16px;
  position: relative;
}

.metric-card::after {
  border-radius: 999px;
  content: "";
  height: 82px;
  opacity: 0.22;
  position: absolute;
  right: -28px;
  top: -22px;
  width: 82px;
}

.metric-card.total::after {
  background: var(--violet);
}

.metric-card.running::after {
  background: var(--blue);
}

.metric-card.failed::after {
  background: var(--red);
}

.metric-card.question::after {
  background: var(--orange);
}

.metric-card span,
.metric-card small {
  display: block;
  font-size: 13px;
}

.metric-card strong {
  display: block;
  font-size: 44px;
  line-height: 1;
  margin: 16px 0 12px;
}

.content-grid,
.right-rail {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head.compact {
  margin-bottom: 10px;
}

.panel h3 {
  font-size: 22px;
  line-height: 1.2;
  margin-top: 4px;
}

.segmented,
.agent-switch {
  /* 狭い画面でもフィルタが潰れないよう横スクロールを許可します。 */
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  overflow-x: auto;
  padding: 4px;
}

.filter,
.agent-filter {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  flex: 1 0 auto;
  min-height: 34px;
  padding: 0 12px;
}

.filter.active,
.filter:hover,
.agent-filter.active,
.agent-filter:hover {
  background: #eef4ff;
  color: #071019;
}

.events {
  display: grid;
  gap: 12px;
}

.event {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 10px minmax(0, 1fr);
  padding: 12px;
}

.event-rail {
  border-radius: 999px;
  min-height: 100%;
}

.event.info .event-rail {
  background: var(--violet);
}

.event.running .event-rail {
  background: var(--blue);
}

.event.success .event-rail {
  background: var(--green);
}

.event.failed .event-rail,
.event.blocked .event-rail {
  background: var(--red);
}

.event-head {
  display: grid;
  gap: 8px;
}

.event h4 {
  font-size: 16px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.status-badge {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
  justify-self: start;
  padding: 5px 9px;
}

.event-meta {
  font-size: 13px;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.message {
  color: var(--soft);
  font-size: 14px;
  line-height: 1.55;
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.usage-list {
  display: grid;
  gap: 10px;
}

.usage-list div {
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px;
}

.usage-list dt {
  font-size: 13px;
}

.usage-list dd {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
}

.signal-panel {
  border-color: rgba(255, 180, 84, 0.28);
}

#last-message {
  color: var(--soft);
  font-size: 15px;
  line-height: 1.55;
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
}

@media (min-width: 560px) {
  /* 小型タブレット以上ではKPIを2列にして一覧性を上げます。 */
  .sidebar,
  .dashboard {
    padding: 20px;
  }

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

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

  .status-badge {
    flex: 0 0 auto;
  }
}

@media (min-width: 860px) {
  /* デスクトップではサイドバー固定と右レールで監視画面らしい密度にします。 */
  body {
    background:
      radial-gradient(circle at top left, rgba(89, 166, 255, 0.18), transparent 34rem),
      radial-gradient(circle at bottom right, rgba(57, 217, 138, 0.13), transparent 28rem),
      linear-gradient(135deg, #080b10 0%, #0f151d 45%, #111820 100%);
  }

  .app-frame {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .sidebar {
    align-content: start;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    gap: 20px;
    height: 100vh;
    padding: 24px;
    position: sticky;
    top: 0;
  }

  .side-nav {
    grid-template-columns: 1fr;
  }

  .side-nav a {
    padding: 11px 12px;
    text-align: left;
  }

  .dashboard {
    gap: 18px;
    padding: 28px;
  }

  .hero {
    align-items: start;
    display: flex;
    gap: 18px;
    justify-content: space-between;
  }

  .hero h2 {
    font-size: clamp(42px, 5vw, 56px);
    line-height: 0.98;
  }

  .toolbar {
    justify-content: flex-start;
    width: auto;
  }

  #last-updated {
    text-align: right;
  }

  .metrics {
    gap: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric-card {
    min-height: 150px;
    padding: 18px;
  }

  .content-grid {
    gap: 18px;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
  }

  .right-rail {
    gap: 18px;
  }

  .panel {
    padding: 18px;
  }

  .panel-head {
    align-items: center;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    margin-bottom: 18px;
  }
}
