<script>
  export let vms = [];

  function tone(state) {
    if (state === 'running') return 'good';
    if (state === 'shut off') return 'warn';
    if (state === 'missing') return 'bad';
    return 'neutral';
  }
  </script>

<section class="grid">
  {#each vms as vm}
    <article class="card">
      <div class="heading">
        <div>
          <p class="eyebrow">{vm.id}</p>
          <h3>{vm.hostname}</h3>
        </div>
        <span class={`badge ${tone(vm.state)}`}>{vm.state}</span>
      </div>

      <dl>
        <div>
          <dt>Domain</dt>
          <dd>{vm.domain}</dd>
        </div>
        <div>
          <dt>Access</dt>
          <dd>{vm.unlocked ? 'available' : 'locked'}</dd>
        </div>
      </dl>
    </article>
  {/each}
</section>

<style>
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
  }

  .card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 1rem;
    box-shadow: var(--shadow);
  }

  .heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
  }

  .eyebrow,
  dt {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  h3 {
    margin: 0.15rem 0 0;
  }

  .badge {
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    text-transform: uppercase;
    font-size: 0.72rem;
  }

  .badge.good { background: rgba(99, 182, 122, 0.15); }
  .badge.warn { background: rgba(213, 166, 75, 0.18); }
  .badge.bad { background: rgba(200, 101, 101, 0.18); }
  .badge.neutral { background: rgba(255, 255, 255, 0.08); }

  dl {
    margin: 1rem 0 0;
    display: grid;
    gap: 0.75rem;
  }

  dd {
    margin: 0.25rem 0 0;
  }
</style>
