:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2129;
  --muted: #5d6673;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --warn: #a86400;
  --warn-bg: #fbefd9;
  --bad: #c0352b;
  --bad-bg: #fbe6e4;
  --idle: #69717d;
  --idle-bg: #eceef1;
  --bar: #2f6fde;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --surface: #1a1e25;
    --surface-2: #222731;
    --border: #2e3440;
    --text: #e6e9ee;
    --muted: #98a1ae;
    --accent: #5b8ff0;
    --ok: #4cc283;
    --ok-bg: #173325;
    --warn: #e9a640;
    --warn-bg: #3a2c14;
    --bad: #f06a5f;
    --bad-bg: #3d1c1a;
    --idle: #98a1ae;
    --idle-bg: #262b34;
    --bar: #5b8ff0;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12151a; --surface: #1a1e25; --surface-2: #222731; --border: #2e3440;
  --text: #e6e9ee; --muted: #98a1ae; --accent: #5b8ff0;
  --ok: #4cc283; --ok-bg: #173325; --warn: #e9a640; --warn-bg: #3a2c14;
  --bad: #f06a5f; --bad-bg: #3d1c1a; --idle: #98a1ae; --idle-bg: #262b34;
  --bar: #5b8ff0; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }

.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 24px; }
.login-card p { margin: 0; }
label { display: grid; gap: 5px; font-weight: 500; }
input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px;
}
.error { color: var(--bad); }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 600; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.pill { font-weight: 500; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* quota */
.quota { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.meter .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.meter .value { font-size: 20px; font-weight: 600; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.meter .value small { font-size: 13px; font-weight: 400; color: var(--muted); }
.track { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.fill { height: 100%; background: var(--bar); border-radius: 99px; transition: width .3s; }
.meter.high .fill { background: var(--warn); }
.meter.full .fill { background: var(--bad); }

/* scope */
.scope { display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 12px 16px; }
.scope-list { display: contents; }
.scope div { display: flex; gap: 8px; align-items: baseline; }
.scope dt { color: var(--muted); font-size: 12px; }
.scope dd { margin: 0; font-weight: 500; }

/* table */
.table-wrap { overflow-x: auto; margin: 0 -16px; }
table.vms { width: 100%; border-collapse: collapse; }
.vms th, .vms td { padding: 9px 16px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; }
.vms th { border-top: 0; color: var(--muted); font-weight: 500; font-size: 12px; }
.vms th.num, .vms td.num { text-align: right; }
.vms tbody tr:hover { background: var(--surface-2); }
.vms .name { font-weight: 500; }
.vms .sub { display: block; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions-col { width: 1%; }
.empty { text-align: center; padding: 24px 0 8px; margin: 0; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 99px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.running { color: var(--ok); background: var(--ok-bg); }
.status.stopped { color: var(--idle); background: var(--idle-bg); }
.status.paused, .status.locked { color: var(--warn); background: var(--warn-bg); }
.status.template { color: var(--muted); background: var(--surface-2); }
.status.template::before { display: none; }

/* toast + dialog */
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px;
  max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.toast.err { background: var(--bad); color: #fff; }
dialog { color: var(--text); max-width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* phone: table rows become cards */
@media (max-width: 760px) {
  .topbar #refreshed { display: none; }
  .table-wrap { margin: 0; overflow: visible; }
  .vms thead { display: none; }
  .vms, .vms tbody, .vms tr, .vms td { display: block; width: 100%; }
  .vms tr { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
  .vms td { border: 0; padding: 3px 0; text-align: left !important; }
  .vms td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
  .vms td.col-id { display: none; }
  .actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 6px; }
}
